c# Bitmap.Save transparancy doesn#39;t save in png(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 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c# Bitmap.Save 透明度不保存在 png 中


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04