Question

I cannot find rigth namespace of that Image^ class I use CLI. It is from http://msdn.microsoft.com/en-us/library/aa970689.aspx that site. The problem is that microsoft does not publicated what I suppose to import, so I even do not know what class they have on their mind.

What include I suppose to add to make this work(Image class)?

Error   1   error C3083: 'Controls': the symbol to the left of a '::' must be a type    C:\Users\Duke\Documents\Visual Studio 2010\Projects\Jpg\Jpg\Jpg.cpp 9   1   Jpg
Error   2   error C2039: 'Image' : is not a member of 'System::Windows' C:\Users\Duke\Documents\Visual Studio 2010\Projects\Jpg\Jpg\Jpg.cpp 9   1   Jpg
Error   3   error C2871: 'Image' : a namespace with this name does not exist    C:\Users\Duke\Documents\Visual Studio 2010\Projects\Jpg\Jpg\Jpg.cpp 9   1   Jpg

    #include "stdafx.h"
    #include "Form1.h"
    #using <mscorlib.dll> //requires CLI
    using namespace System;
    using namespace System::IO;
    using namespace System::Windows::Media::Imaging;
using namespace System::Windows::Controls::Image;
        Stream^ imageStreamSource = gcnew FileStream("C:\Users\Duke\Desktop\heart.jpg", FileMode::Open, FileAccess::Read, FileShare::Read);

                JpegBitmapDecoder^ decoder = gcnew JpegBitmapDecoder(imageStreamSource, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
                BitmapSource^ bitmapSource = decoder->Frames[0];//< --mamy bitmape
                // Draw the Image
                Image^ myImage = gcnew Image();
                myImage->Source = bitmapSource;
                myImage->Stretch = Stretch::None;
Was it helpful?

Solution

Given that you're working with WIC classes (eg. BitmapDecoder and BitmapSource), you'll want to avoid anything involving the System::Drawing namespace which is all old-school GDI. Either make no reference to those namespaces in your using directives, or explicitly use the whole System::Windows::Media namespace.

The specific Image class you're after is probably System::Windows::Controls::Image (docs here).

You'll need to add a reference to the WIC wrappers and a few supporting assemblies in your project in order to link to the appropriate DLLs.

  • PresentationCore has all of the main image codecs and manipulation classes that you want, this is mentioned in the JpegBitmapDecoder documentation.
  • WindowsBase is needed for a few additional dependencies used by the WIC wrappers (Freezable and DispatcherObject).
  • System.Xaml may also arise as a dependency... in a WIC-using C# project I have here, building without that assembly generates an error due to the absense of System.Windows.Markup.IUriContext. This may be an artefact of my use of the WIC assemblies, however (but I certainly make no use of Xaml nor IUriContext).
  • PresentationFramework provides the Image class and its dependencies, as mentioned in the appropriate documentation

OTHER TIPS

System::Windows::Controls namespace (for Image class) needs PresentationFramework.dll as reference, and System::Windows::Media::Imaging (for BitmapSource class) namespace needs PresentationCore.dll.

Did you include these two references in your project?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top