2

The following code illustrates the problem I am faced with. If I load a CR2 file with

var format = FREE_IMAGE_FORMAT.FIF_RAW;
retVal = FreeImage.LoadBitmap("AJ2A1447.cr2", ref format);

then I successfully load the RAW file. If I use something like

using (Stream stream = new FileStream("AJ2A1447.cr2", FileMode.Open, FileAccess.Read))
{
  var format = FREE_IMAGE_FORMAT.FIF_RAW;
  freeImageHandle = FreeImage.LoadFromStream(stream, ref format);
  if (freeImageHandle.IsNull)
  {
    throw new Exception("Unable to load image from stream");
  }

  retVal = FreeImage.GetBitmap(freeImageHandle);
}

then I am unsuccessful as freeImageHandle is null. I use FileStream for a test, the real code will use a MemoryStream.

Any clue to why LoadFromStream fails?

Lars Nielsen
  • 365
  • 1
  • 2
  • 14

2 Answers2

1

there is number of RAW formats and I doubt if FREE_IMAGE_FORMAT.FIF_RAW knows how to decode CR2.

http://en.wikipedia.org/wiki/Raw_image_format

Try to use windows generated bitmap and jpg to see if your code works.

Na Na
  • 818
  • 3
  • 13
  • 19
  • The LoadBitmap approach shouldn't also fail if this was true? Meaning Freeimage needs to know how to decode the CR2 file in both cases. I use FREE_IMAGE_FORMAT.FIF_RAW in both cases. – Lars Nielsen Aug 10 '13 at 10:34
  • use appropriate formats for bmp and jpg images: FIF_BMP, FIF_JPEG. – Na Na Aug 10 '13 at 10:41
  • I am trying to load a CR2 file (canon raw format) so I am using the right format. – Lars Nielsen Aug 10 '13 at 11:59
  • I know ;) but test your code against other formats. This should work. I doubt if Canon RAW format is supported. – Na Na Aug 10 '13 at 13:42
  • Tell me, why the Loadbitmap method wouldn't fail if CR2 format is not supported? – Lars Nielsen Aug 10 '13 at 14:38
  • Lars, Canon CR2 is not supported. .NET don't know how to decode it. http://stackoverflow.com/questions/4111939/loading-canon-cr2-files-in-net – Na Na Aug 11 '13 at 06:31
  • You do know that Freeimage's .net code is basically only wrapping the C code that does the magic? – Lars Nielsen Aug 11 '13 at 13:07
0

FreeImage uses libRawLite to read Canon CR2 raw format. However, libRawLite does not support the sRAW CR2 files.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174
  • I tried with different RAW formats: RAW, SRAW1 and SRAW2 plus with different cameras. Not much of a difference as they all failed. I am successful when I add the load flag: `FREE_IMAGE_LOAD_FLAGS.RAW_PREVIEW` which I know means: "Tries to load the JPEG preview image, embedded in Exif Metadata or load the image as RGB 24-bit if no preview image is available". If I try with flag `FREE_IMAGE_LOAD_FLAGS.RAW_DISPLAY` then I just get a white BPM out of it. So right now I am trying to figure out if I get some embedded JPEG when I add the PREVIEW flag – Lars Nielsen Aug 12 '13 at 11:13
  • I ended up programming a solution in C++ using Libraw so no longer an issue for me. Thanks for your help – Lars Nielsen Aug 13 '13 at 18:39