Resizing jpg images

Xee

Member
Joined
Apr 6, 2003
Messages
10
Anyone know how I would go about resizing jpg images? I want to be able to make thumbnails of jpg images while keeping the original the same size. Usually, I would use Microsoft Photo Editor and resize it to 25% of its original size and then save it with a different name, but when Im dealing with 15 or more images, that can get tedious.

Im not expecting any complete code; just a helpful point in the right direction and Ill take it from there. Thanks a lot.


-Xee
 
You would use the Bitmap class to load them from disk in to memory, then create another bitmap passing the old bitmap and the new size to the constructor. You can then use the bitmaps Save method.

To automate this for, say, a whole directory of images, youd use System.IO.Directory.GetFiles to get all the files ending in bmp in to a string array and loop through it.
 
Divil, Im trying to do this but, Im probably being thick here, there isnt a constructor for Bitmap that accepts a bitmap as an argument. there is one that accepts a graphics object but I cant get that to work either :-(
 
The Bitmap class is derived from Image, which is one of the constructors. You can even use a Bitmap without casting, as in:
C#:
Bitmap b = new Bitmap(@"c:\mybitmap.bmp");
Bitmap b2 = new [b]Bitmap(b, 100, 100);[/b]
b2.Save(@"c:\mynewsmallerbitmap.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

Note the last param to Save. This is where you define the type of picture. Even though you may save the file as "image.BMP", if you dont specify the ImageFormat, youll get a PNG formatted image.

-Nerseus
 
thanks a ton... this helped me a lot. Been stuck on how to resize images for a while.

However, one small snag: How do I do it from a console application?

Another question, is there any way to use the System.Drawing... Classes from a Console Application?
 
Right Click the References Directory in the Solution Explorer, choose Add and find System.Drawing.dll, add it to the project then use the Imports System.Drawing to make use of it
 
Originally posted by Nerseus
The Bitmap class is derived from Image, which is one of the constructors. You can even use a Bitmap without casting, as in:
C#:
Bitmap b = new Bitmap(@"c:\mybitmap.bmp");
Bitmap b2 = new [b]Bitmap(b, 100, 100);[/b]
b2.Save(@"c:\mynewsmallerbitmap.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
-Nerseus

in the first line of code
whats the @ symbol next to NewBitmap?
How do you write the same in vb.net?
 
Back
Top