[英]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.