Reading raw image files in c#

北战南征 提交于 2019-12-04 03:33:44

问题


How do i decode/open raw image files like .CR2 or .NEF and .ARW without having the codec installed, something like lightroom open raw files ? My code look like this:

if (fe == "CR2" | fe == "NEF" | fe == "ARW" )
{
    BitmapDecoder bmpDec = BitmapDecoder.Create(new Uri(op.FileName), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);

    BitmapSource bsource = bmpDec.Frames[0];
    info_box.Content = fe;
    imgControl.Source = bsource;
}

This work only with the raw codecs installed and dont work with ARW format.


回答1:


If you don't have a codec installed, then you'll have to read the raw image data and convert it to a bitmap or other format that you can read. In order to do that, you need a copy of the format specification so that you can write code that reads the binary data.

I strongly recommend getting a codec, or finding code that somebody has written that already handles the conversion. But if you really want to try your hand at writing image format conversion code, your first order of business is to get the format specification.

A quick Google search on [CR2 image format] reveals this Canon CR2 Specification. Truthfully, I don't know how accurate that is, but it looks reasonable. A little time with a search engine will probably reveal similar documents for the other formats.

Be forewarned: writing these conversions can be a very difficult task. Again, I recommend that you find some existing code that you can leverage.




回答2:


If you insist on not installing a codec, then your best bet might be these:

http://www.cybercom.net/~dcoffin/dcraw/
- written in C, supports most cameras

http://sourceforge.net/projects/dcrawnet/
- apparently a (partial?) port of DCRAW to C#, but project does not seem to be active



来源:https://stackoverflow.com/questions/17976231/reading-raw-image-files-in-c-sharp

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