locked
Displaying a RAW Image (g.CANON OR NIKON) in a WPF application RRS feed

  • Question

  • Windows Photo Gallery can display CANON or Nikon RAW files if the codecs have been installed on the system. I am trying to develop a simple application that can display RAW files, HD Photos and photos in Jpeg, TIFF formats etc. I have successfully displayed the HD Photos using WPF and the System.Windows.Controls.Image control. I would like to display a RAW file through this application. I have already installed the CANON RAW codec v 1.2. I am working with VS .NET 2005, with .NET 3.0 SDK and have installed the CANON RAW codec. I am working on a XP machine.

    Friday, January 25, 2008 6:34 PM

Answers

  • You should be able to do this using BitmapImage, BitmapFrame, or any of the BitmapSource classes in WPF. If you take a look at WIC Tools, this uses WPF to try out CODECs after some setup.

    Friday, January 25, 2008 10:11 PM

All replies

  • You should be able to do this using BitmapImage, BitmapFrame, or any of the BitmapSource classes in WPF. If you take a look at WIC Tools, this uses WPF to try out CODECs after some setup.

    Friday, January 25, 2008 10:11 PM
  • These samples don't seem to be using WPF. By WPF I mean using the namespace in

    System.Windows.Media.Imaging with references to PresentationCore and PresentationFramework. If I am not able to use System.Windows.Media.Imaging is there any example to interoperabilty with WIC and WPF that I can reference?

     

    Friday, January 25, 2008 11:12 PM
  • CACUser: Have just found your post here so will contiue this thread from now on.

     

    How are you trying to view the images? I have tried a sample CR2 file I have in a simple WPF window using <Image Source="filename"/> and it seems to work for me (on Vista however). Does this very simple approach work for you, or are you creating your BitmapSource in a different way?

     

    Since you can get the HDPhoto support etc. to work, I have one thought on the problem. The underlying WIC architecture allows you (or as in your case though WPF, then the WPF team) to specify an vendor GUID when creating a bitmap decoder. If you specify 'null' then you get decoders created by all vendors. From Reflector you can see that one of the code paths in WPF specify to only return Microsoft codecs. Not sure how my code avoids this though (maybe what is being done will be more obvious when the full framework code, with comments, is released).

     

    Andy

    Sunday, January 27, 2008 12:29 PM
  • Just to let you know, the Framework source (including WPF) is available. See Shawn Burke's blog post for details on how to activate this in VS 2008.

     

    http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx

     

    One note, it is release (optimised) code, so expect execution out of sequence etc. So it is best to set your breakpoints a little before the code you are interested in and step through (or breakpoint on all the lines).

    Monday, January 28, 2008 8:11 AM
  • Sorry about the delay in getting back. Some other fire came up...

    Thanks for your reply. From a "pure" WPF app I was able to display a CR2 file as you suggested.

     

    I have C# app that uses PresentationCore and PresentationFramework namespaces. I am simply trying to display images - jpg,wdp, cr2 etc.

    This is what I use to show the wdp ( HD Photo):

     

    Stream imageStreamSource = new FileStream(@"C:\temp\IMG_1012.wdp", FileMode.Open, FileAccess.Read, FileShare.Read);
    WmpBitmapDecoder decoder = new WmpBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
    BitmapSource bitmapSource = decoder.Frames[0];
    System.Windows.Controls.Image imgDisplayed = new System.Windows.Controls.Image();
    imgDisplayed.Source = bitmapSource;

     

    If I substitute a CR2 file instead of a wdp file which type of decoder should I use? Also is there a better way of doing this in a C# app?

     

    Thanks.

    Friday, February 1, 2008 11:46 PM
  • Got it by using the following:BY using Codec discovery

    BitmapDecoder bmpDec = BitmapDecoder.Create(new Uri(@"C:\XXX.CR2"), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);

    BitmapSource bitmapSourcetest = bmpDec.Frames[0];

    //set image source

    imgDisplayed4.Source = bitmapSourcetest;

     

    Thanks.
    Saturday, February 2, 2008 12:45 AM
  • In general using BimapDecoder.Create(...) is the best route for loading images as this should work for any installed codec. The WmpBitmapDecoder class is specific for HDPhoto files, as for example JpegBitmapDecoder is for jpeg files. The BimapDecoder.Create(...) will determine the type of the file from the stream or uri, and return the correct type for this format. In the case of raw files (or any codec that is not known by WPF) then you actually get an UnknownBitmapDecoder instance returned - NB: This is internal so you cannot cast to this type.

     

    Andy

    Sunday, February 3, 2008 5:49 PM
  • hi CACUser,

    Can u explain about "Displaying a RAW Image (g.CANON OR NIKON) in a WPF application" or Send me the sample source code..?

    Thanx in advance..Smile
    Monday, February 11, 2008 7:36 AM
  • As a first step dowmload and install the Canon or Nikon RAW codec that supports WIC. These are usually available from their respective websites. I took the following steps to display them from a C# application using VS .NET 2005.

    Add references to PresentationCore and Presentation foundation. You will need to download .NET 3.0 SDk to do this.Add the following using statements:

    using System.Windows.Controls; // to use the Image control

    using System.Windows.Media.Imaging;// to use WIC.

     

    Add an Image control to windows form

    Image imgDisplayed4 = new Image();

    BitmapDecoder bmpDec = BitmapDecoder.Create(new Uri(@"C:\Test\Test11.CR2"), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);

    BitmapSource bitmapSourcetest = bmpDec.Frames[0];

    //set image source

    imgDisplayed4.Source = bitmapSourcetest;

     

     

    Should display the RAW file now.

     

     

    Monday, February 11, 2008 5:08 PM