简体   繁体   English

在c#中读取原始图像文件

[英]Reading raw image files in c#

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 ? 如何在没有安装编解码器的情况下解码/打开.CR2或.NEF和.ARW等原始图像文件,像lightroom打开原始文件? 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. 这只适用于安装的原始编解码器,不适用于ARW格式。

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 . 快速谷歌搜索[CR2图像格式]显示此佳能CR2规格 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. 同样,我建议您找到一些可以利用的现有代码。

If you insist on not installing a codec, then your best bet might be these: 如果你坚持不安装编解码器,那么最好的选择可能是:

http://www.cybercom.net/~dcoffin/dcraw/ http://www.cybercom.net/~dcoffin/dcraw/
- written in C, supports most cameras - 用C语言编写,支持大多数相机

http://sourceforge.net/projects/dcrawnet/ http://sourceforge.net/projects/dcrawnet/
- apparently a (partial?) port of DCRAW to C#, but project does not seem to be active - 显然是DCRAW到C#的(部分?)端口,但项目似乎没有活动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM