[英]How to set transparent background in Bitmap from BitmapImage?
我有將BitmapImage轉換為Bitmap的功能:
private Bitmap BitmapImage2Bitmap(BitmapImage bitmapImage)
{
using(MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bitmapImage));
enc.Save(outStream);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);
return new Bitmap(bitmap);
}
}
我的圖片具有黑色背景(如.PNG則具有透明背景)。
如何使它們始終具有透明背景?
如果您的顯示技術是WinForms,則答案是:您不能做到。 WinForms已有數十年歷史,可以支持Display方面的適當透明度。
Windows窗體非常擅長提高透明度,但效果卻不那么出色: https ://www.codeproject.com/Articles/25048/How-to-Use-Transparent-Images-and-Labels-in-Window
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.