C#png透明背景图转变白背景bmp图
透明背景图的png直接用转换成bmp打开会显示背景为黑色,如果想要白色背景图的处理方法:
if (File.Exists(pngPath)) { var bmpPath = string.Format("C:\\Temp\\{0}.bmp", userId); using (var bmpImg = Image.FromFile(pngPath)) { using (var b = new Bitmap(bmpImg.Width, bmpImg.Height)) { b.SetResolution(img.HorizontalResolution, img.VerticalResolution); using (var g = Graphics.FromImage(b)) { g.Clear(Color.White); g.DrawImageUnscaled(bmpImg, 0, 0); } b.Save(bmpPath, ImageFormat.Bmp); b.Dispose(); } bmpImg.Dispose(); } }