Saving Dynamic images RRS feed

  • Question

  • User-1676599296 posted
    Hi, The following code is for generated a thumbnail image dynamically. However, I cannot figure out how to save the image once it is generated. I've tried using the system.IO to complete this task, but was unsuccessful. Any help would be appreciated. Dim imageWidth As Integer = 100 Dim imageHeight As Integer = 100 Dim scale As Double ' Set the filename. Dim fileName As String fileName = Server.MapPath("hospital1.jpg") ' create a new bitmap image Dim CurrentImageBitmap As Bitmap = New Bitmap(fileName) ' work out new sizes If(CurrentBitmap.Height < CurrentBitmap.Width) Then scale = (imageHeight)/CurrentBitmap.Width Else scale = (imageWidth)/CurrentBitmap.Height End If ' Set new width and height. Dim newWidth As Integer = CInt(scale*CurrentBitmap.Width) Dim newHeight As Integer = CInt(scale*CurrentBitmap.Height) ' create a new image from original Dim OutputBitmap As Bitmap = New Bitmap(CurrentBitmap, newWidth, newHeight) ' set the mime type Response.Clear() Response.ContentType="image/jpg" ' send the image to the viewer OutputBitmap.Save(Response.OutputStream, ImageFormat.Jpeg) ' clean up OutputBitmap.Dispose() CurrentBitmap.Dispose()
    Thursday, August 5, 2004 4:15 PM

All replies

  • User-1372641848 posted
    Code which you listed will stream image to web browser, if you want to save image to file system then there is overload method. OutputBitmap.Save("Path to save image", ImageFormat.Jpeg)
    Friday, August 6, 2004 8:07 AM