Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
3.80/5 (3 votes)
See more:
How do I convert a png picture to jpg format?
Posted

Try:
C#
Image png = Image.FromFile(@"D:\Temp\MyPic.png");
png.Save(@"D:\Temp\MyPic.jpg", ImageFormat.Jpeg);
 
Share this answer
 
 
Share this answer
 
Use GDI+

C#
//Make sure this is in your using block
using System.Drawing;
using System.Drawing.Imaging;

private bool ChangeToJPG(string file)
{
    try
    {
        //In case you're fussy about PNGs
        if (!file.ToLower().EndsWith(".png"))
           throw new NotImplementedException("Not a png file");
        if (!System.IO.File.Exists(file))
           throw new NotImplementedException("File not found");

        Image png = Image.FromFile(file);
        png.Save(file.Replace(".png", ".jpg").Replace(".PNG", ".JPG"), ImageFormat.Jpeg);
        return true;
    }
    catch
    {
        return false;
    }
}


Simple ;-)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900