I have code to upload and save a picture as a thumbnail. The thumbnail code works great. The problem is I'm trying to then crop the thumbnail to a square pixel of 55 by 55. I'm using code that normally would be saving the image to a screen, but I'm saving the image as a file into a web directory. The thumbnail saves as 55 x 55, but it is not being cropped. It's just being squished to fit into the 55 square. Again, thumbnail code works great - I show some of it here just to show where I'm getting the image to work with to crop it. Can someone look at my code starting at:
STARTING HERE FOR CROPPING THUMBNAIL IMAGE
and see if I'm either cropping wrong, or saving the cropped image wrong? Thanks.
code getting ready for thumbnail creation......
Response.ContentType = "image/jpeg"
'call the function to create the thumbnail
thumb = Ettienne_Thumbnail(origina
limg, height, width)
'make the quality of thumbnail as good as possible
Dim codecEncoder As ImageCodecInfo = GetEncoder("image/jpeg")
Dim quality As Integer = 100
Dim encodeParams As New EncoderParameters(1)
Dim qualityParam As New EncoderParameter(Imaging.E
ncoder.Qua
lity, quality)
encodeParams.Param(0) = qualityParam
thumbHeight = thumb.Height
thumbWidth = thumb.Width
******** STARTING HERE FOR CROPPING THUMBNAIL IMAGE
' create a new bitmap that will be the end result for the cropped picture
Dim bitthumb As New System.Drawing.Bitmap(55, 55, PixelFormat.Format24bppRgb
)
' create a graphics object to work with
Dim graphicthumb As Graphics = Graphics.FromImage(bitthum
b)
' blank the image
graphicthumb.Clear(Color.B
lue)
'# crop and resize!
' Set a unit of measurement as pixel
' could have used Inch, Point, etc
Dim unit = GraphicsUnit.Pixel
' Draw image using the Pixel unit
' set above
graphicthumb.DrawImage(thu
mb, New Rectangle(0, 0, 55, 55), New Rectangle(0, 0, thumbWidth, thumbHeight), unit)
' set the content type
Response.ContentType = "image/jpeg"
' SAVE THE IMAGE USING THE ENCODE PARAMETERS
bitthumb.Save(pathForThumb
, codecEncoder, encodeParams)
thumbHeight = bitthumb.Height
thumbWidth = bitthumb.Width
Start Free Trial