JPG image actually saved as PNG

A

Al

private void GetResizedImage(string imagePath, int width, int height, string destinationDirectory, string destinationFileName)
{
System.Drawing.Image image = System.Drawing.Image.FromFile( imagePath, true );

Bitmap thumbnail = new Bitmap( width, height, image.PixelFormat );

Graphics graphics = Graphics.FromImage( thumbnail );
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

Rectangle rectangle = new Rectangle(0, 0, width, height);
graphics.DrawImage( image, rectangle );

image.Dispose();
thumbnail.Save( destinationDirectory + "\\" + destinationFileName + "." + System.Drawing.Imaging.ImageFormat.Jpeg);
thumbnail.Dispose();
}
 
C

Chris Lovett

Try

thumbnail.Save( destinationDirectory + "\\" + destinationFileName + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

private void GetResizedImage(string imagePath, int width, int height, string destinationDirectory, string destinationFileName)
{
System.Drawing.Image image = System.Drawing.Image.FromFile( imagePath, true );

Bitmap thumbnail = new Bitmap( width, height, image.PixelFormat );

Graphics graphics = Graphics.FromImage( thumbnail );
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

Rectangle rectangle = new Rectangle(0, 0, width, height);
graphics.DrawImage( image, rectangle );

image.Dispose();
thumbnail.Save( destinationDirectory + "\\" + destinationFileName + "." + System.Drawing.Imaging.ImageFormat.Jpeg);
thumbnail.Dispose();
}
 
A

Al

That worked beautifully! Thank you.


Try

thumbnail.Save( destinationDirectory + "\\" + destinationFileName + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

private void GetResizedImage(string imagePath, int width, int height, string destinationDirectory, string destinationFileName)
{
System.Drawing.Image image = System.Drawing.Image.FromFile( imagePath, true );

Bitmap thumbnail = new Bitmap( width, height, image.PixelFormat );

Graphics graphics = Graphics.FromImage( thumbnail );
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

Rectangle rectangle = new Rectangle(0, 0, width, height);
graphics.DrawImage( image, rectangle );

image.Dispose();
thumbnail.Save( destinationDirectory + "\\" + destinationFileName + "." + System.Drawing.Imaging.ImageFormat.Jpeg);
thumbnail.Dispose();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top