Reading RAW image files as GDI+ bitmaps [closed]

巧了我就是萌 提交于 2019-11-28 07:03:06

Disclaimer: I work at Atalasoft.

Our DotImage Photo Pro product can do this. If you want to try to do it yourself, look into wrapping the opensource DCRaw or look at how Paint.NET does it (I think there's a RAW plugin for it)

The DotImage Photo Pro component worked well, but I had a problem extracting the preview image from raw files using it. It is also outside my budget for this project.

But, I found the code for a RAW plugin for Paint.NET here and it was quite simple to adapt to my needs. The plugin runs the DCRaw executable usign Process.Start and reads its output from the StandardOutput stream. Quite simple and fast! :-)

Edit:

The link to the plugin doesn't work anymore, but here is the code I used to extract the images. The following code extracts the jpg-preview stored in the raw file. If you want the full image you should remove the -e argument. But be aware that for some cameras you will get a ppm-image that GDI+ cannot read.

public Stream GetImageData(string inputFile, string dcRawExe)
{


    var startInfo = new ProcessStartInfo(dcRawExe)
    {
        Arguments = "-c -e \"" + inputFile + "\"",
        RedirectStandardOutput = true,
        UseShellExecute = false
    };

    var process = Process.Start(startInfo);

    var image = Image.FromStream(process.StandardOutput.BaseStream);

    var memoryStream = new MemoryStream();
    image.Save(memoryStream, ImageFormat.Png);

    return memoryStream;
}

Also, you will need a copy of DCRaw. I used the DcrawMS.exe from this site: http://www.insflug.org/raw/Downloads/

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!