Convert png image to jpg C#
Hello. There is an image in png format. How to convert it to jpg / jpeg correctly ? I do it like this:
Image bmp = new Bitmap(path); //путь к картинке
bmp.Save(filename, ImageFormat.Jpeg);
But for some reason it seems to me that this is too simple and in which case my conversion will be "crooked"...
5
2 answers
In general, you do everything like this, only you could add another compression ratio.
Bitmap bmp1 = new Bitmap(@"c:\TestPhoto.jpg");
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
System.Drawing.Imaging.Encoder myEncoder =
System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
myEncoderParameter = new EncoderParameter(myEncoder, 100L);//100L - сжатие. Можно выставить 0L
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(@"c:\TestPhotoQualityHundred.jpg", jgpEncoder,
myEncoderParameters);
3
Author: Andrew, 2016-12-30 18:44:28
class Program
{
static void Main(string[] args)
{
// Загружаем картинку.
System.Drawing.Image image1 = System.Drawing.Image.FromFile(path);
//Сохраняем в JPEG .
image1.Save(@"C:\image_xxx.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
1
Author: Александр Пузанов, 2016-12-28 09:44:10