R
rhungund
Hi all. I'm using a simple thumbnail generating script in VB.NET/GDI.
It uses the GetThumbnailImage method.
It works great when resizing gifs. But when I resize a jpeg the
quality looks terrible. Here's a code snippet. Thanks.
Dim fullSizeImg as System.Drawing.Image
fullSizeImg =
System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
width = fullSizeImg.width
height = fullSizeImg.height
imageHeight = height * (imageWidth/width)
'Do we need to create a thumbnail?
Response.ContentType = "image/jpeg"
If imageHeight > 0 and imageWidth > 0 then
Dim dummyCallBack as System.Drawing.Image.GetThumbNailImageAbort
dummyCallBack = New _
System.Drawing.Image.GetThumbnailImageAbort(AddressOf
ThumbnailCallback)
Dim thumbNailImg as System.Drawing.Image
thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth,
imageHeight, _
dummyCallBack,
IntPtr.Zero)
thumbNailImg.Save(Response.OutputStream, ImageFormat.jpeg)
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.jpeg)
End If
It uses the GetThumbnailImage method.
It works great when resizing gifs. But when I resize a jpeg the
quality looks terrible. Here's a code snippet. Thanks.
Dim fullSizeImg as System.Drawing.Image
fullSizeImg =
System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
width = fullSizeImg.width
height = fullSizeImg.height
imageHeight = height * (imageWidth/width)
'Do we need to create a thumbnail?
Response.ContentType = "image/jpeg"
If imageHeight > 0 and imageWidth > 0 then
Dim dummyCallBack as System.Drawing.Image.GetThumbNailImageAbort
dummyCallBack = New _
System.Drawing.Image.GetThumbnailImageAbort(AddressOf
ThumbnailCallback)
Dim thumbNailImg as System.Drawing.Image
thumbNailImg = fullSizeImg.GetThumbnailImage(imageWidth,
imageHeight, _
dummyCallBack,
IntPtr.Zero)
thumbNailImg.Save(Response.OutputStream, ImageFormat.jpeg)
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.jpeg)
End If