Jump to content

how to save cropped image


dev

Recommended Posts

hi,please help me, i am stucked here. i am using the following code to crop image to a certain with and height but how to save the cropped image? i am new to .net<%@ Page Language="vb" Debug="true" %><%@ import namespace="system.drawing" %><%@ import namespace="system.drawing.imaging" %><%@ import namespace="system.drawing.drawing2d" %><%Dim strFilename as StringDim i as System.Drawing.ImagestrFilename = Server.MapPath("horse.jpg")i = System.Drawing.Image.FromFile(strFilename)Dim b As New System.Drawing.Bitmap(400, 200, PixelFormat.Format24bppRgb)Dim g as Graphics = Graphics.FromImage(B)g.Clear(Color.Blue) Dim unit = GraphicsUnit.Pixelg.DrawImage(i, New Rectangle(0, 0, 400, 400), New Rectangle(0, 0, 200, 200), unit)Response.ContentType = "image/jpeg"b.Save(Response.OutputStream, ImageFormat.Jpeg)b.Dispose()g.Dispose()i.Dispose()%>Please tell me, with thanks

Link to comment
Share on other sites

try this
b.Save("horse_cropped.jpg", ImageFormat.Jpeg)

i am getting this error msg:Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.Source Error: Line 17: g.DrawImage(i, New Rectangle(0, 0, 400, 400), New Rectangle(0, 0, 200, 200), unit)Line 18: Response.ContentType = "image/jpeg"Line 19: b.Save("hh.jpg", ImageFormat.Jpeg)Line 20: Line 21: b.Dispose()
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...