转换PNG与GDI +(C#)为GIF [英] convert png to gif with gdi+ (C#)

查看:200
本文介绍了转换PNG与GDI +(C#)为GIF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有哪些必须被转换为GIF文件PNG文件。
有一个透明部分在里面,当我保存它的透明部分为黑色的透明代替。这里
是我的代码:

i have a png file which must be converted to a gif file. There is a transparent part in it, and when i save it the transparent part is black in stead of transparent. here's my code:

FileStream imgStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write);

Image.FromFile(imageInput).Save(imgStream, ImageFormat.Gif);



在这里,imageinput是完整路径到我的PNG和输出文件是.gif扩展的filefullpath。

here, imageinput is the fullpath to my png, and output file is the filefullpath with .gif extension.

你能看到什么是错在这里?

can you see what is wrong here?

米歇尔

推荐答案

PNG使用Alpha透明度,这意味着每个像素,除了它的颜色,还包含一个值表示它(称为如何透明字母)。这允许PNG图像为半透明

PNG uses alpha transparency, meaning that each pixel, in addition to its color, also contains a value denoting how transparent it is (called alpha). This allows PNG images to be semi-transparent.

GIF图像使用二进制透明度,这意味着每个像素只包含一种颜色,但可能的颜色之一是透明

GIF images use binary transparency, meaning that each pixel only contains a color, but one of the possible colors is Transparent.

因此,PNG的透明部分会变成黑色,而是完全透明的。结果
当您保存GIF文件,阿尔法值被忽略,导致黑色。

Therefore, the transparent parts of the PNG will be colored black, but completely transparent.
When you save the GIF file, the alpha value is ignored, resulting in black.

<击>您需要通过图像中的像素循环,更换任何颜色其中有0带有alpha Color.Transparent

修改:您需要调用 MakeTransparent

EDIT: You need to call MakeTransparent

这篇关于转换PNG与GDI +(C#)为GIF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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