将位图保存为32bpp不会保持透明度

using (var bmp = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppArgb)) using (var g = Graphics.FromImage(bmp)) { g.Clear(Color.Transparent); g.DrawImage(image, 0, 0); bmp.Save("image.bmp", ImageFormat.Bmp); } 

问题应该是明确的:为什么保存到BMP 会将透明度变为黑色 ,而保存到PNG 会保留它

只是为了澄清: 图像采用Format8bppIndexed格式,其调色板确实包含透明色(例如,它正确地绘制在窗体/图片框上)

编辑:我的错, Bitmap.Save()实际上以Format32bppRgb格式保存BMP,即使位图格式是Format32bppArgb

这是因为默认情况下, bmp文件格式不支持png文件格式的透明度。

如果你想要透明度,你将不得不使用png。 压缩算法是无损的,因此您不会在图像中获得伪像。 该文件也会占用更少的磁盘空间。