Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 it's original size and then save it with a different name, but when I'm dealing with 15 or more images, that can get tedious.

 

I'm not expecting any complete code; just a helpful point in the right direction and I'll take it from there. Thanks a lot.

 

 

-Xee

  • *Gurus*
Posted

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 bitmap's Save method.

 

To automate this for, say, a whole directory of images, you'd use System.IO.Directory.GetFiles to get all the files ending in bmp in to a string array and loop through it.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • 3 weeks later...
Posted
Divil, I'm trying to do this but, I'm probably being thick here, there isn't a constructor for Bitmap that accepts a bitmap as an argument. there is one that accepts a graphics object but I can't get that to work either :-(
My website
  • *Experts*
Posted

The Bitmap class is derived from Image, which is one of the constructors. You can even use a Bitmap without casting, as in:

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 don't specify the ImageFormat, you'll get a PNG formatted image.

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • 1 month later...
Posted

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?

Posted
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
.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted
The Bitmap class is derived from Image, which is one of the constructors. You can even use a Bitmap without casting, as in:

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?

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...