Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
hi all
i am using C#. i want to Convert Transparent PNG to JPG with white Background Color
normally i am using these code.
Image img = Image.FromFile(filename);
img.Save(newFilename, System.Drawing.Imaging.ImageFormat.Jpeg);
it works fine. but background color is black.
Is there any way to make the background white instead?
best regards
NazHim
For example :
Bitmap bmp = new Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.White);
g.DrawImage(img, new Rectangle(new Point(), img.Size), new Rectangle(new Point(), img.Size), GraphicsUnit.Pixel);
}
bmp.Save(newFilename, System.Drawing.Imaging.ImageFormat.Jpeg);