C# png格式图像转jpg时透明背景变为黑色问题

Image img = Image.FromFile(filename);
// Assumes myImage is the PNG you are converting
using (var b = new Bitmap(img.Width, img.Height)) {
    b.SetResolution(img.HorizontalResolution, img.VerticalResolution);

    using (var g = Graphics.FromImage(b)) {
        g.Clear(Color.White);
        g.DrawImageUnscaled(img, 0, 0);
    }

    // Now save b as a JPEG like you normally would
    b.Save(@路径, System.Drawing.Imaging.ImageFormat.Jpeg);
}
亲测可用
原文链接 https://stackoverflow.com/questions/6513633/convert-transparent-png-to-jpg-with-non-black-background-colo

猜你喜欢

转载自blog.csdn.net/a_post/article/details/79912885