Win7:Image.FromFile 上的内存不足异常 [英] Win7: Out of Memory exception on Image.FromFile

查看:59
本文介绍了Win7:Image.FromFile 上的内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 vista 之前,以下源代码在 Windows 上运行良好.在 Windows 7(和新的 .net 3.5)中,当我尝试从尼康 D90 加载原始图像文件时,它总是会产生内存不足异常.
有些人可能会说不支持加载 nef",但在 vista 之前它确实运行良好,只有 Windows 7 破坏了它,所以我不同意.

The following piece of source does run nicely with Windows up until vista. With Windows 7 (and the new .net 3.5) it always produces an out of memory exception, when I try to load a raw image file from my Nikon D90.
Some might say "loading nef's is not supported", but it did run nicely up until vista, only Windows 7 broke it, so I'd disagree.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace QuickImageLoader
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
      DialogResult res = openFileDialog1.ShowDialog();
      if (res == DialogResult.OK)
      {
        pictureBox1.Image = Image.FromFile(openFileDialog1.FileName); // crash happens
        pictureBox1.Refresh();
      }
    }
  }
}

下载示例 nef 文件以重现错误.

这是 Windows 7 中的错误吗?在 .net 3.5 中?或者它不应该与 XP/Vista 一起工作?

Is this a bug in Windows 7? In .net 3.5? Or is it something that should have never worked with XP/Vista?

[更新] 因为有些人既不知道也没有阅读我上面的介绍:像这样加载 nef 确实可以在 XP/Vista 上运行而无需安装 Nikon Raw Codec.安装编解码器并不能解决问题(伙计们,这与编解码器无关sigh).

[Update] Since a few people neither know nor read my introduction above: loading the nef like this does work on XP/Vista without installing the Nikon Raw Codec. And installing the codec does not solve the problem (folks, it got nothing to do with the codec sigh).

推荐答案

对于来自 Nikon Coolpix P5000 的 JPEG 照片,我可以确认此行为.

I can confirm this behavior for JPEG photos coming from a Nikon Coolpix P5000.

文件内部结构似乎有问题,混淆了GDI+ jpeg loader.我使用外部图像查看器将图像重新编码为jpg,然后一切正常.我无法确认此行为是否仅在 Win7 上发现

It seems that there is some problem with the internal structure of the file, which confuses the GDI+ jpeg loader.I used an external image viewer just to recode the images as jpg and then everything went to normal. I cannot confirm if this behavior is found only on Win7

那么有没有人找到原因?或者它可能是 GDI+ 中的一个错误?

So did anybody found the cause of this? Or perhaps it's a bug in GDI+?

这篇关于Win7:Image.FromFile 上的内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆