Is there a good way to read RAW image files (especially Canon CR2 and Adobe DNG files) as GDI+ bitmaps that is reasonably fast?
I found an example running under WPF that would read an image using any installed image codec and then display it in an image control. And I modified this example to create a GDI+ bitmap by writing the WPF image to a MemoryStream and creating the Bitmap from that. But this process is slow! Horribly slow! Opening a simple image takes around 10 seconds on my computer. This solution also requires references to the WPF assemblies and that doesn't feel right, especially not since I would like to run the code in an ASP.NET project.
There are programs that will do batch conversions of the images, but I would prefer converting the images dynamically when requested.
So, any suggestions?
A bitmap stores data for an image and its attributes in pixel format. The Bitmap class, which is inherited from the Image class, encapsulates a graphic bitmap in GDI+.
Well, GdipCreateBitmapFromGraphics creates a new, blank, usually solid black bitmap in memory which can be used with GDI+, not a clipped copy of the image. GDI bitmap handle and a GDIPLUS image handle are not the same.
Windows GDI+ provides the Image class for working with raster images (bitmaps) and vector images (metafiles). The Bitmap class and the Metafile class both inherit from the Image class.
GDIPLUS has two flat API: GdipCreateBitmapFromHBITMAP and GdipCreateHBITMAPFromBitmap, that shoud do the conversion, but indeed they do not work with 32-bit bitmap when using an alpha channel. Convert a GDIPLUS image handle into a GDI32 bitmap handle. BYVAL hImage AS LONG _ ' The GDIPLUS image handle to convert from.
Here is a C# port of dcraw, albeit rather old (v8.88) which could be adapted to include newer Canon models:
https://sourceforge.net/projects/dcrawnet/
EDIT :
I just got it to work in my own project for reading EXIF data from RAW files:
using dcraw;
at the top.Declare these lines of code:
DcRawState state = new DcRawState();
state.inFilename = filename;
state.ifp = new RawStream(filename);
Identifier id = new Identifier(state);
id.identify(state.ifp);
Now check out all the goodies inside state (assuming your RAW file is supported and didn't cause an exception ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With