How to do image conveting

Hi guys

 

I need to be able to convet image types on my web server can anybody tell me how best to do this

 

Paul



Answer this question

How to do image conveting

  • Robert Kozak

    what exactly do you mean by "stream it to the client browser" Just redirect the page to the resized/reformatted image.

  • kopo

    The easiest way is to load the file with the Image class and then save it again to a new file while specifying the format you want:

    System.Drawing.Image image = System.Drawing.Image.FromFile("originalFile.jpg");

    image.Save("convertedFile.png", System.Drawing.Imaging.ImageFormat.Png);



  • cmazur

    Thank you

    sorry about the other thread wasn't sure weather this was a framework or C# problem

    The fine example works if I save the save the file do you know if it is posable to convent the image object and then stream it to the client brower

    Paul


  • gdvl

     

    have done the convert do something along thease line to deivler the file to the client

     

    Response.Clear();

    Response.ContentType = "application/octet-stream";

    Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");

    Response.Flush();

    Response.WriteFile(image)

     

    if just "Just redirect the page to the resized/reformatted image" I will end up with temp files on the server So don't want to write the file to file system if can avoid and if I do have to I wish to able to delete it before the page exits


  • Michael Chancey

    That was simple

    does anybody know what the server hit on doing this type of work is

    I am working on image libarary and one of the requerments to be able to provide different size and formats images has abody got experence converting/resizing on the fly

    ie. keep the oringal large format on the server and convert/resize as a download stream ( load the image from the file system do the convert and the stream the the result to the client web brouser)

    the other way what to make diffent versions on upload as save all the version on the server which seems a waste of server space

    Paul

  • Senkwe Chanda

    Please only post 1 topic:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=568626&SiteID=1

     

    As for your question on "server hit" - depends on alot of things such as the server configuration/performance, what format you are going to be saving the image to, the size of the image etc... however it shouldnt be a big hit at all.

    If its going to be saved over a network stream then there will be a small hit I believe.

    Probably best doing something like:

    1) take file

    2) resize/convert

    3) get link of resized/converted file and show to user

     

    this should be ok - you may want to take a look at some perf counters or something to see how long it takes for 1 process to do, or time it using the DateTime/TimeSpan classes

     



  • How to do image conveting