Resize Images

  • Thread starter Thread starter SlasherStanley
  • Start date Start date
S

SlasherStanley

BlankHi

How do you resize a jpg file. I want to open a file (c:\abc.jpg 800 x 600) and resize it as 120 x 100, I then want to save it as c:\abc_t.jpg.

Thanks

Slasher
 
Blank
One way of doing this is to load your picture into an Image or Bitmap object. Then create a new Image or Bitmap object of the size that you want and get a Graphics object for it. Finally use Graphics.DrawImage to draw the complete old picture to the new smaller picture. All that is left is for you to save your smaller picture to file.

I think microsoft.public.dotnet.framework.drawing is a better place to post image type questions.


Robby
VB.Net

Hi

How do you resize a jpg file. I want to open a file (c:\abc.jpg 800 x 600) and resize it as 120 x 100, I then want to save it as c:\abc_t.jpg.

Thanks

Slasher
 
If you want to use .NET to resize an image, you will need to use
Image.FromFile to get an Image object from the JPG file. Then use the
Image.GetThumbnailImage() method resize the image to the size you want.
You can then use Image.Save to write the image out to a file. I don't
know whether Image remembers what format it was on input (probably
not), so you may have to use myImage.Save(outputFileName,
ImageFormat.Jpeg) in order to get JPEG output.
 
BlankThanks for everybody's input.

This is how I have done it. The only thing I have not done, is to reduce the colour depth of the thumbnail.Because of this the physical size of the thumbnail is quite large. Any ideas????


private void btnResize_Click(object sender, System.EventArgs e)

{

String[] files = Directory.GetFiles("c:\\images");

foreach (string imagefile in files)

{

FileInfo FileProps =new FileInfo(imagefile);

string filename = FileProps.Name;

string fileextension = FileProps.Extension;


string [] Split = filename.Split(new Char [] {'.'}); //removes all character after and including (.)

filename = Split[0].ToString();

if (fileextension.ToLower() == ".jpg")

{

Image OriginalImage;

OriginalImage= System.Drawing.Image.FromFile(imagefile);


Image thumbnailImage;

thumbnailImage = OriginalImage.GetThumbnailImage(150, 113, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

thumbnailImage.Save("c:\\images\\" + filename + "t.jpg");

}

}

}


public bool ThumbnailCallback()

{

return true;

}





Hi

How do you resize a jpg file. I want to open a file (c:\abc.jpg 800 x 600) and resize it as 120 x 100, I then want to save it as c:\abc_t.jpg.

Thanks

Slasher
 
Back
Top