相关疑难解决方法(0)

将图像转换为位图会将背景变为黑色

我需要将图像转换为位图.

最初,gif以字节形式读入,然后转换为Image.

但是,当我尝试将图像转换为位图时,我的图片框中显示的图形在以前是白色时具有黑色背景.

这是代码:

    var image = (System.Drawing.Image)value;
        // Winforms Image we want to get the WPF Image from...
        var bitmap = new System.Windows.Media.Imaging.BitmapImage();
        bitmap.BeginInit();
        MemoryStream memoryStream = new MemoryStream();
        // Save to a memory stream...
        image.Save(memoryStream, ImageFormat.Bmp);
        // Rewind the stream...
        memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
        bitmap.StreamSource = memoryStream;
        bitmap.EndInit();
        return bitmap;
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么背景会变黑以及我如何阻止它这样做.

谢谢

c# image bitmap

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

bitmap ×1

c# ×1

image ×1