c# Bitmap.Save transparancy 不保存为 png

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)