Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading RAW image files as GDI+ bitmaps [closed]

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?

like image 1000
Rune Grimstad Avatar asked Oct 22 '08 21:10

Rune Grimstad


People also ask

What is bitmap in GDI?

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+.

What is the difference between gdipcreatebitmapfromgraphics and 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.

What is Windows GDI+ image class?

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.

How to convert a GDIPlus image to a GDI32 bitmap?

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.


1 Answers

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:

  1. Open project properties and set Output Type to Class Library.
  2. Recompile.
  3. Add a reference to the DLL in your own project.
  4. Add using dcraw; at the top.
  5. 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 ;)

like image 92
glenneroo Avatar answered Oct 25 '22 08:10

glenneroo