cropping an image to size...?

M

Milsnips

hi there,

i'm uploading to my photo gallery and this is what i'm after..

When user uploads image, i automatically create a 75x75 thumbnail, however
using the GetThumbnailImage function drops the quality and distorts it, so
what i would like to do is:

resize the original image to:
Width: 75px
Heigh: relative size to image

then any additional size outside the bounds of 75x75 to be cropped so i get
a non-distorted thumbnail image.

This is the code i have so far...any help appreciated,
-----------------------------------------------------------------
Sub ResizeImage(ByVal s As IO.Stream, ByVal outputFilename As String)
Dim oImage As System.Drawing.Image =
System.Drawing.Image.FromStream(s)

Dim newWidth, newHeight As Integer
newWidth=75
newHeight=75

'''here i'd like to resize the original image first to width=75,
height = relative to width resize, then crop off any unneeded bits of the
image outside the 75x75 bounds.

Dim bmpOut As New Bitmap(newWidth, newHeight)
Dim g As Graphics = Graphics.FromImage(bmpOut)
g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(Brushes.White, 0, 0, newWidth, newHeight)
g.DrawImage(oImage, 0, 0, newWidth, newHeight)
oImage.Dispose()

bmpOut.Save(outputFilename, System.Drawing.Imaging.ImageFormat.Jpeg)
g.Dispose()
g = Nothing
bmpOut.Dispose()
bmpOut = Nothing
oImage.Dispose()
oImage = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top