c# Bitmap.Save 透明度不保存在 png 中 [英] c# Bitmap.Save transparancy doesn't save in png

查看:55
本文介绍了c# Bitmap.Save 透明度不保存在 png 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将具有透明度的位图类保存为具有透明度的 png 文件.我运气不好.

I'm trying to save a Bitmap class that has transparancy as a png file with transparancy. I'm having no luck.

这就是我正在做的事情

Bitmap ret = new Bitmap(bWidth, bHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

保存

ret.Save(filename, ImageFormat.Png);

我也尝试使用文件流保存文件,这没有任何区别.

I also tried saving the file with a filestream, and that made no difference.

当图像在图片框中时,透明度存在,但是当我保存时,我只是得到黑色背景.

When the image is in a Picture box the transparancy exists, but when I save i I just get a black background.

我真的不想使用任何 3rd 方代码,他们找到了一种方法,我也想这样做.

I really don't want to use any 3rd party code, they found a way to do it, I'd like to also.

谢谢.

推荐答案

我假设对话框的 FilterIndex 从 0 开始......但实际上它从 1 开始,所以我的图像被保存为使用 alpha 透明度的 Gif,而 gif 不支持 alpha 透明度.所以我的问题实际上出在对话框上.

I assumed that the FilterIndex of a dialog box started at 0...but it actually starts at 1, so my images were being saved as Gifs using alpha transparancy, and gif doesn't support alpha transparency. So my problem was actually with the dialog box.

这篇关于c# Bitmap.Save 透明度不保存在 png 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆