Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Canon .CR2 files in .NET

I am trying to process Canon RAW .CR2 files using C#. My code is as follows:

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

The first few lines seem to run without a hitch, but the line

bmEnc.Save(ms);

just hangs without completing and without raising any exception.

Has anyone had any success with this?

like image 916
Darren Oster Avatar asked Sep 06 '25 04:09

Darren Oster


1 Answers

Know this is a old thread but I found a nice easy to use library (Magick.NET).

How to do a conversion:

using (MagickImage image = new MagickImage("StillLife.CR2"))
{
    image.Write("StillLife.jpg");
}

https://github.com/dlemstra/Magick.NET/blob/master/docs/ReadRawImageFromCamera.md

Details of nuget package installation:

Install-Package Magick.NET-Q16-AnyCPU

https://github.com/dlemstra/Magick.NET

like image 183
P6345uk Avatar answered Sep 07 '25 19:09

P6345uk