如何在位图中设置位图中的透明背景



我有该功能将位映射转换为位图:

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已有几十年的历史来支持显示侧的适当透明度。

Windows表单非常擅长于透明度,但不是很好:https://www.codeproject.com/articles/25048/how-to-to-to-cuse-use-transparent-images-images-images-and-labels-and-labels-inbels-inbels-inbels-ingel-windowpin/p>

最新更新