Image resizing and file resizing

Single Coil

New member
Joined
May 11, 2008
Messages
3
Programming Experience
Beginner
Hello,

I am developing a program which will open an image on to the form (in a picturebox) and then the user can resize it with 2 methods. I just want to discuss the 1st method now :)

The goal of this program (for this method) is to save the image that is loaded in the picturebox with a size of 600 pixels on the longest side and with a file size of less than 100Kb.

I know how to load and save the image, but am having some trouble with saving the image with the given image size and file size.

I was wondering if someone can point me in the right direction or give some help on this.
I am using VB.net 2008

Thanks :)
 
For the image size, you can create a new Image with the size you need. You would check which side of the original image is the longest, get the ratio you need to scale it by and then create a new Image object that has the scaled down size and draw the initial image on it. Then you can just save the image as is.

Now if you want to limit file size as well, I think it is not possible to tell the file size of an image using JPEG compression until it actually has been compressed, so you'd need to

1. Draw the image on the scaled down image.
2. Save the image to a buffer with JPEG compression and see the size of the buffer.
3. If the buffer is small enough, go to step 5, otherwise, go to step 3.
4. Create a new image with a new maximum size (that is, say 10 pixels less than the previous try) and go back to step 1.
5. Save the buffer to the file.
 
Back
Top