After cropping the image, I want the cropped image to overwrite the old image. I use code:
Private Function Crop(ByVal Source As Bitmap, ByVal x As Int32, ByVal y As Int32, ByVal width As Int32, ByVal height As Int32) As Bitmap
Dim Cropped As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(Cropped)
g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
Dim rect As New Rectangle(0, 0, width, height)
g.DrawImage(Source, rect, x, y, width, height, GraphicsUnit.Pixel)
Return Cropped
End Function
i = System.Drawing.Image.FromFile(imagePath)
cropped=Crop(i,x,y,w,h)
i.dispose()
response.contenttype="image/gif"
cropped.save(imagePath,ImageFormat.gif)
cropped.dispose()
I got error: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
But if I change the code to:
imagepath= newImagePath
cropped.save(Server.MapPath(imagepath),ImageFormat.Gif)
This time the cropped image can be save to newImagePath.
How should I do to save the image back to the old image name? Thanks for help.
Private Function Crop(ByVal Source As Bitmap, ByVal x As Int32, ByVal y As Int32, ByVal width As Int32, ByVal height As Int32) As Bitmap
Dim Cropped As New Bitmap(width, height)
Dim g As Graphics = Graphics.FromImage(Cropped)
g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
Dim rect As New Rectangle(0, 0, width, height)
g.DrawImage(Source, rect, x, y, width, height, GraphicsUnit.Pixel)
Return Cropped
End Function
i = System.Drawing.Image.FromFile(imagePath)
cropped=Crop(i,x,y,w,h)
i.dispose()
response.contenttype="image/gif"
cropped.save(imagePath,ImageFormat.gif)
cropped.dispose()
I got error: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
But if I change the code to:
imagepath= newImagePath
cropped.save(Server.MapPath(imagepath),ImageFormat.Gif)
This time the cropped image can be save to newImagePath.
How should I do to save the image back to the old image name? Thanks for help.