c# Bitmap.Save transparancy doesn#39;t save in png(c# Bitmap.Save transparancy 不保存为 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 transparancy 不保存为 png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c# Bitmap.Save transparancy 不保存为 png
基础教程推荐
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
