在C#中将原始图像转换为位图

4 c# image bitmap

我的代码当前如下所示:

if (fe == "CR2")
{
    Image img = null;
    byte[] ba = File.ReadAllBytes(open.FileName);
    using (Image raw = Image.FromStream(new MemoryStream(ba)))
    {
        img = raw;
    }
    Bitmap bm = new Bitmap(img);
    pictureBox1.Image = bm;
    statusl.Text = fe;
}
Run Code Online (Sandbox Code Playgroud)

当我打开RAW图像时,程序停止运行,Visual Studio会说:

参数无效:Image raw = Image.FromStream(new MemoryStream(ba))

请帮忙!如何获取要在PictureBox中显示的RAW文件?

Mar*_*Put 5

像这样创建位图:

Bitmap bmp = (Bitmap) Image.FromFile(open.FileName);
Run Code Online (Sandbox Code Playgroud)

或不使用位图:

 this.pictureBox1.Image = Image.FromFile(open.FileName);
Run Code Online (Sandbox Code Playgroud)

WPF示例:

BitmapDecoder bmpDec = BitmapDecoder.Create(new Uri(origFile),
BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
BitmapEncoder bmpEnc = new BmpBitmapEncoder();
bmpEnc.Frames.Add(bmpDec.Frames[0]);
Stream ms = new MemoryStream();
bmpEnc.Save(ms);
Image srcImage = Bitmap.FromStream(ms);
Run Code Online (Sandbox Code Playgroud)