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

Muh*_*man 0 asp.net image

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

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

另外,我想在此上下文中讨论ImageMagic的功能.

Tim*_*mes 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);        
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 投票没有解释?我只是以公平的名义投了票...... (2认同)
  • 我已经放弃了为什么答案得到了回落.谢谢你的投票!:) (2认同)