Resize an Image Properly?
It's me again...
I've spent a few hours today trying to figure out how to properly resize a jpg image programmatically...
hellswraith has helped me out a bunch already, giving me a very nice example to start off with... but i've found that using GDI+ (at least in the way i'm using it) doesn't properly.. my resized image looks to be very low quality, even when i try saving it with the jpg quality at 100...
here's the sub i'm using to resize the image:
VB Code:
Function ResizeImage(ByVal MaxWidth As Integer, ByVal MaxHeight As Integer, ByVal Image As Bitmap) As Bitmap
Dim ScaleFactor As Decimal
Dim NewSize As SizeF
If CInt(Image.Size.Width) > MaxWidth Or CInt(Image.Size.Height) > MaxHeight Then
If CInt(Image.Size.Width) > CInt(Image.Size.Height) Then
'Image Width is too big
ScaleFactor = CDec(MaxWidth / CInt(Image.Size.Width))
Else
'Image Height is too big
ScaleFactor = CDec(MaxHeight / CInt(Image.Size.Height))
End If
NewSize.Width = Image.Size.Width * ScaleFactor
NewSize.Height = Image.Size.Height * ScaleFactor
'Return the resized image
ResizeImage = Image.GetThumbnailImage(NewSize.Width, NewSize.Height, Nothing, Nothing)
End If
End Function
Now, here's the original image i'm starting with:
http://public.pc-innovations.com/Red...s_Original.jpg
Here's the image that my code resizes: (Keep in mind, the way i saved this image, i used jpeg encoder at a quality of 100)
http://public.pc-innovations.com/Red...ResizedBad.jpg
And Finally, here's what Photoshop ends up with when it resizes my image to the same size as my code:
http://public.pc-innovations.com/Red...esizedGood.jpg
So, as you can see, my code doesn't do the job... So, i'm still looking for a proper way to do this, be it through a 3rd party .NET library, or code... i would PREFER to have code to do this in .NET myself, but if nothing else, i guess 3rd party would have to suffice... thanks for the help guys!