转换原始图像在C#中为位图 [英] Convert raw images to bitmap in c#

查看:134
本文介绍了转换原始图像在C#中为位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code目前看起来是这样的:

My code currently looks like this:

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;
}

当我打开RAW图像程序停止和Visual Studio说:

When I open a RAW image the program stops and Visual Studio says:

参数是无效的:图片的原始= Image.FromStream(新的MemoryStream(BA))

Parameter is not valid: Image raw = Image.FromStream(new MemoryStream(ba))

请帮帮忙!我怎样才能得到一个RAW文件,以在PictureBox显示?

Please help! How can I get a RAW file to show in a PictureBox ?

推荐答案

创建位图是这样的:

Bitmap bmp = (Bitmap) Image.FromFile(open.FileName);

使用或不使用位图:​​

or without using bitmap:

 this.pictureBox1.Image = Image.FromFile(open.FileName);

例如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);

这篇关于转换原始图像在C#中为位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆