I'm trying to generate thumbnails on the fly without a horrible loss in quality so I've found that using the Drawing.Graphics class might be the best way.
Now the problem is that the resulting image is just the source file without any resizing. Seems that the drawimage method just draws something on the screen and since this code is getting called from the src property of an image tage on another page the
drawing does no good. I need to somehow insert the results of the drawimage into the output stream so it is returned to the calling page. I can't seem to locate a function/method or workaround to do this. Anyone have any ideas or perhaps a better way to
approach this?
Your code is drawing the thumbnail overtop of the original image. You need to create a new image, and draw the original image onto that. The critical lines are below:
Dim thumbnail As New System.Drawing.Bitmap(100,100) ' Set the thumbnail size here
Dim myresizer As Drawing.Graphics = Drawing.Graphics.FromImage(thumbnail)
myresizer.DrawImage(fullSizeImg, 0, 0, thumbnail.Width, thumbnail.Height)
thumbnail.Save(Response.OutputStream, ImageFormat.Jpeg)
* The above code has not been tested, but it should give you an idea of how to approach this.
Marked as answer by boondocks5 on Sep 04, 2007 07:48 PM
boondocks5
Member
29 Points
14 Posts
Drawing.Graphics issue
Sep 04, 2007 06:22 PM|LINK
I'm trying to generate thumbnails on the fly without a horrible loss in quality so I've found that using the Drawing.Graphics class might be the best way.
dim
imageUrl as String = Request.QueryString("img")Dim
fullSizeImg As System.Drawing.ImagefullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
Dim myresizer As Drawing.Graphicsmyresizer = Drawing.Graphics.FromImage(fullSizeImg)
myresizer.InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
Response.ContentType =
"image/jpg"myresizer.DrawImage(fullSizeImg, 0, 0, 100, 100)
'CInt(imgWidth), CInt(imgHeight))fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg)
fullSizeImg.Dispose()
Now the problem is that the resulting image is just the source file without any resizing. Seems that the drawimage method just draws something on the screen and since this code is getting called from the src property of an image tage on another page the drawing does no good. I need to somehow insert the results of the drawimage into the output stream so it is returned to the calling page. I can't seem to locate a function/method or workaround to do this. Anyone have any ideas or perhaps a better way to approach this?
Benners_J
Contributor
2857 Points
442 Posts
Re: Drawing.Graphics issue
Sep 04, 2007 07:00 PM|LINK
Your code is drawing the thumbnail overtop of the original image. You need to create a new image, and draw the original image onto that. The critical lines are below:
* The above code has not been tested, but it should give you an idea of how to approach this.
boondocks5
Member
29 Points
14 Posts
Re: Drawing.Graphics issue
Sep 04, 2007 07:48 PM|LINK
that did it, thanks for the help