如何将图像从任何格式转换为JPG格式?

时间:2012-04-25 10:14:20

标签: asp.net image

我尝试使用ImageFormat class将png格式图像转换为JPG格式。然后我们尝试使用另一个验证图像的工具验证图像,发现只是扩展名已更改但格式仍为PNG。

我们如何将给定的iamge转换为JPG格式?我们使用写类吗?我们需要调用哪些方法。请提供详细信息。

此外,我还想讨论ImageMagic在此背景下的功能。

1 个答案:

答案 0 :(得分:6)

您需要将图像重新保存为.JPG格式。

您可以使用System.Drawing命名空间执行此操作。看看这里,看看这是否完成了工作http://msdn.microsoft.com/en-us/library/twss4wb0(v=vs.90).aspx

class Program
{
    static void Main(string[] args)
    {
        // Load the image.
        System.Drawing.Image image1 = System.Drawing.Image.FromFile(@"C:\test.bmp");

        // Save the image in JPEG format.
        image1.Save(@"C:\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

        // Save the image in GIF format.
        image1.Save(@"C:\test.gif", System.Drawing.Imaging.ImageFormat.Gif);

        // Save the image in PNG format.
        image1.Save(@"C:\test.png", System.Drawing.Imaging.ImageFormat.Png);        
    }
}