![](/img/trans.png)
[英]How can I convert a JPEG image to a PNG one with transparent background?
[英]How can I convert image on the hard disk png to be transparent?
private void ConvertImagestoTransparent(string filename)
{
var image = new Bitmap(filename, PixelFormat.Format32bppArgb);
using (var g = Graphics.FromImage(image))
{
g.DrawLine(Pens.Red, 0, 0, 135, 135);
}
}
这给我错误,新的位图没有获取文件名:
错误2参数2:无法从'System.Drawing.Imaging.PixelFormat'转换为'bool'
也没有得到位图。
在构造函数中:
DirectoryInfo d = new DirectoryInfo(@"C:\temp\images\");
Files = d.GetFiles("*.png");
是否可以将png图像转换为透明图像? 会失去质量吗?
您使用的Bitmap
构造函数仅用于加载现有图像。 如果你想创建一个,那么你需要使用这一个是这样的:
var image = new Bitmap(theWidth, theHeight, PixelFormat.Format32bppArgb);
然后,您可以将图像保存到以下文件中:
image.Save(filename);
对于第二个问题,“将png图像转换为透明图像”是什么意思? 是否要从图像中删除背景色?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.