Last post Apr 14, 2009 09:25 AM by fedro321
Apr 14, 2009 08:15 AM|fedro321|LINK
I'm using the method getThumbnailImage to resize some images I have stored in a directory. I can create the image in memory using the from file method, but then run into difficulty when I attempt to create a resized copy of it.
It works with one of the 5 images I am trying to re-size as this image is tiny at 4.49kb and actually scales the image up. The others are fairly small in size also, so I'm bemused as to why it won't work with all the images.
Here's the code: Line 37 is where the problem comes from.
public class Resize
private string location;
public Resize(string location)
this.location = location;
public bool dummyFunction()
public Image getResizedImage(int max)
Image.GetThumbnailImageAbort myCallback =
fullSizeImage = Image.FromFile(location);
int width = fullSizeImage.Width;
int height = fullSizeImage.Height;
if (width > height)
newWidth = max;
newHeight = height * (newWidth / width);
newHeight = max;
newWidth = width * (newHeight / height);
resizedImage = fullSizeImage.GetThumbnailImage(newWidth, newHeight, myCallback, IntPtr.Zero);
Any help would be greatly appreciated.
Apr 14, 2009 08:26 AM|SGWellens|LINK
Try changing the ints to floats or doubles and cast them back to ints when setting the images size.
When you do this with ints, 50 / 70, the answer is zero.
Apr 14, 2009 09:25 AM|fedro321|LINK
Thanks for that. As with most problems it was a school boy error on my part.