Jump to content
Sign in to follow this  
dev

how to save cropped image

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

Share this post


Link to post
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()

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...