|
-
Apr 8th, 2003, 11:48 PM
#1
Thread Starter
Fanatic Member
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:

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)

And Finally, here's what Photoshop ends up with when it resizes my image to the same size as my code:

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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|