dev Posted September 3, 2008 Share Posted September 3, 2008 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 More sharing options...
aspnetguy Posted September 3, 2008 Share Posted September 3, 2008 try this b.Save("horse_cropped.jpg", ImageFormat.Jpeg) Link to comment Share on other sites More sharing options...
dev Posted September 3, 2008 Author Share Posted September 3, 2008 try thisb.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 More sharing options...
aspnetguy Posted September 3, 2008 Share Posted September 3, 2008 it's been a while since I have done anything like this. I'll see if I can find some code samples later today.For now take a look here http://www.informit.com/guides/content.asp...&seqNum=296. Take a look at the how they have the bitmap object. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.