1

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

Download a sample nef file to reproduce error.

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

[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).

Sam
  • 28,421
  • 49
  • 167
  • 247
  • 4
    It seems that "Out of memory" is the default way for that method to signal an error. *Any* error: "If the file does not have a valid image format or if GDI+ does not support the pixel format of the file, this method throws an OutOfMemoryException exception." – Joey Oct 29 '09 at 14:36
  • I tried this code on four different installations of Windows 7. I even scrapped a system, reinstalled Windows 7 to be sure I got a clean box. Still I get the error. So, how do I resolve that error? – Sam Oct 29 '09 at 14:41
  • Does an analysis with Process Monitor show any missing files/registry keys? – Dirk Vollmar Oct 29 '09 at 14:50
  • Something that I haven't seen mentioned - have you tried opening the file in question in the native Windows image viewer? I'd imagine that uses the same set of codecs that .NET uses. It might not help, but it'll at least tell you if the problem is a missing codec or not. – iKenndac Oct 29 '09 at 14:52
  • divo, I can't find any abnormalities in process monitor. Of course there is a lot of noise (33,000 events) going on, so there might be something hidden. But since a fresh install did not fix, I'd be surprised. iKenndac, the native image viewer shows the file if, and only if, the nikon raw codec is installed (which works on all these systems). The load problem above persists regardless of the codec. This problem has no connection to the installation state of the codec. – Sam Oct 29 '09 at 15:40
  • Sam, does the image viewer show the file without the third party codec installed on Vista? BTW: When I was talking about codecs above, I was referring to the built-in ones. If your system can read an image file it *will* have a codec for it somewhere, even if it came with the system. – iKenndac Oct 29 '09 at 15:52
  • iKenndac, no, as I wrote above: the image viewer shows the image if and only if the codec is installed. The test program above does work (or, on W7, not work) regardless of the codec. Installing (or removing) the codec does not change the behaviour of the code above, neither on XP/Vista nor on Windows 7. The problem is not connected to the installation state of the codec. – Sam Oct 29 '09 at 16:00
  • The codec is not needed to *read* the file, it is needed to interpret the raw image data (which the image viewer needs to show the picture). – Sam Oct 29 '09 at 16:01
  • Just a thought: Could this be a 32 bit vs 64 bit issue? Are your vista and Windows7 versions both 32 bit or both 64 bit? – Chris Dunaway Oct 29 '09 at 21:58
  • Chris, I tried this on x86 and x64 systems, on different hardware. I even tried to compile the program for x86 platform. All to no effect. The problem is independent of 32/64 bit. – Sam Oct 30 '09 at 08:59
  • I have just run across this problem, with the same results you have had. Did you even find a solution? – xpda Jan 05 '10 at 04:28
  • Sadly, I have not found any solution to this. – Sam Jan 05 '10 at 09:45

3 Answers3

2

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

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

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

Andon
  • 36
  • 2
0

By itself, Image.FromFile does not support a lot of image types, but more can be installed.

So, did you install something into Vista that made this work? Like a Nikon Codec pack or something that would add that support?

And that error message means one of two:

  • The image file is not supported (which can, as pointed out above, be fixed by installing the appropriate codecs or whatnot)
  • The image file is indeed supported, but the file contents are corrupt, so some value inside that is used to allocate a memory struct is way beyond bounds (like an image that says it is 217273373 pixels wide)

I see from the comments that there is some discussion here. I do not know whether Microsoft explicitly pulled the format by themselves, or was forced to do so, but I can confirm that GDI+ does not support NEF on my Windows 7 installation, so regardless of whether XP or Vista supported it, and regardless of the reason for why it is no longer support, Windows 7 does not support NEF-loading in GDI+ out of the box.

So you need to install something.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • I can confirm that it works out of the box on Vista. Just tried and I didn't install a raw codec. – Joey Oct 29 '09 at 14:35
  • The code does work without installing the Nikon Raw Codec on XP/Vista. – Sam Oct 29 '09 at 14:38
  • i am unconvinced by the down-votes; these posts contain useful information, even if it didnt work. – Pondidum Oct 29 '09 at 14:42
  • 1
    So, perhaps that is your answer... Perhaps support for that codec was not included in Windows 7. This happens frequently as licensing issues cause MS to pull native support for certain things. I would research the coded support differences between them. – Brian Rudolph Oct 29 '09 at 14:44
  • Well, I don't think wrong information is useful, rather the opposite. Try for yourself, you'll notice my example code and file will work with Vista/Xp and won't for Windows 7, which no part of the answer explains. – Sam Oct 29 '09 at 14:46
  • Brian, you might be right, I'd consider your information as a useful answer, but this was not in the answer - and SO does not allow me to take the downvote back just because some comments where added. :( – Sam Oct 29 '09 at 14:48
  • Oh, might I add, installing the Nikon Raw Codec does not resolve the issue. And of course GDI+ does not support display of NEF files. But it did support reading the metatags from NEF, by exactly this method. So there must be something else broken. – Sam Oct 29 '09 at 15:06
0

Did you installed the Nikon Raw Codec? Windows itself (and .NET Framework) does not know to handle Nikons Raw format.

Arthur
  • 7,939
  • 3
  • 29
  • 46
  • It does here on Vista. And I never installed any raw codec on this machine. – Joey Oct 29 '09 at 14:35
  • The code works on XP/Vista without the Nikon Raw Codec. On Windows 7 it does not work, regardless of any Raw Codecs. – Sam Oct 29 '09 at 14:37