将 RAW 图像文件读取为 GDI+ 位图

发布于 2024-07-08 10:50:13 字数 1560 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

勿忘初心 2024-07-15 10:50:13

免责声明:我在 Atalasoft 工作。

我们的 DotImage Photo Pro 产品可以做到这一点。 如果你想尝试自己做,请考虑包装开源 DCRaw 或看看 Paint.NET 是如何做的(我认为有一个 RAW 插件)

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)

悸初 2024-07-15 10:50:13

DotImage Photo Pro 组件运行良好,但我在使用它从原始文件中提取预览图像时遇到问题。 这也超出了我对该项目的预算。

但是,我在 这里找到了 Paint.NET RAW 插件的代码< /a> 适应我的需求非常简单。 该插件使用 Process.Start 运行 DCRaw 可执行文件,并从 StandardOutput 流中读取其输出。 非常简单又快速! :-)

编辑:

插件的链接不再起作用,但这是我用来提取图像的代码。 以下代码提取原始文件中存储的 jpg-preview。 如果你想要完整的图像,你应该删除 -e 参数。 但请注意,对于某些相机,您将获得 GDI+ 无法读取的 ppm 图像。

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

此外,您还需要一份 DCRaw 的副本。 我使用了此站点中的 DcrawMS.exe: http://www.insflug.org/raw/Downloads /

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/

烟酉 2024-07-15 10:50:13

这是 dcraw 的 C# 端口,尽管相当旧 (v8.88),可以对其进行修改以包括较新的佳能型号:
https://sourceforge.net/projects/dcrawnet/

编辑:< br>
我刚刚让它在我自己的项目中工作,用于从 RAW 文件读取 EXIF 数据:

  1. 打开项目属性并将输出类型设置为类库
  2. 重新编译。
  3. 在您自己的项目中添加对 DLL 的引用。
  4. 在顶部添加 using dcraw;
  5. 声明这些代码行:

    DcRawState 状态 = new DcRawState(); 
      state.inFilename = 文件名; 
      state.ifp = new RawStream(文件名); 
    
    
      标识符 id = 新标识符(状态); 
      id.identify(state.ifp); 
      

现在检查 state 内的所有好东西(假设您的 RAW 文件受支持并且没有导致异常;)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文