在C#中的图像删除透明度 [英] Remove transparency in images with C#
本文介绍了在C#中的图像删除透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
没有人知道从如去除透明光滑/快捷方式PNG格式/ TIFF格式等,并用白色背景取代它?
does anyone know a smooth / fast way of removing transparency from e.g. pngs/tiffs etc and replacing it with a white background?
基本上我需要这个是我需要创建PDF / A兼容的图像,这可以根据该规范,有-NO-透明度(因此固定的白色背景是罚款)。
Basically what I need this for is I need to create PDF/A compatible images, which may, according to the spec, have -no- transparency (and therefore a fixed white background is fine).
任何意见/建议?
干杯和放大器;谢谢, -Jörg
Cheers & thanks, -Jörg
推荐答案
您可以创建一个位图的大小相同PNG,画一个白色的矩形,然后绘制图像在它的上面。
You could create a bitmap the same size as the png, draw a white rectangle and then draw the image on top of it.
void RemTransp(string file) {
Bitmap src = new Bitmap(file);
Bitmap target = new Bitmap(src.Size.Width,src.Size.Height);
Graphics g = Graphics.FromImage(target);
g.DrawRectangle(new Pen(new SolidBrush(Color.White)), 0, 0, target.Width, target.Height);
g.DrawImage(src, 0, 0);
target.Save("Your target path");
}
这篇关于在C#中的图像删除透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文