Convert raw images to bitmap in c#

bitmap, c#, image

Solution

Create the bitmap like this:

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

or without using bitmap:

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

Example 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);

Problem

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; } ``` When I open a RAW image the program stops and Visual Studio says: Parameter is not valid: Image raw = Image.FromStream(new MemoryStream(ba)) Please help! How can I get a RAW file to show in a PictureBox ?

Original source

Related problems