2012-11-21 28 views
0

我無法找到該圖像^我使用CLI的rigth命名空間。它是從http://msdn.microsoft.com/en-us/library/aa970689.aspx那個網站。問題在於微軟沒有公佈我想要導入的內容,所以我甚至不知道他們的想法是什麼。什麼是正確的包括圖像CLI類

什麼包括我想補充做這項工作(圖片類)?

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; 

回答

0

既然你與WIC類(如:BitmapDecoderBitmapSource)工作,你要避免任何涉及System::Drawing命名空間是所有老派GDI。請不要在您的using指令中提及這些命名空間,也不要明確使用整個System::Windows::Media命名空間。

您正在使用的具體的Image類可能是System::Windows::Controls::Image(文檔號here)。

您需要在項目中添加對WIC包裝和幾個支持程序集的引用,以鏈接到相應的DLL。

  • PresentationCore擁有所有你想要的主圖像編解碼器和操作類的,這個JpegBitmapDecoder文件中被提及。
  • WindowsBase對於WIC包裝(FreezableDispatcherObject)使用的一些附加依賴項是必需的。
  • System.Xaml也可能出現作爲一個依賴...在WIC使用C#項目我在這裏,沒有該組件產生的錯誤,由於缺乏System.Windows.Markup.IUriContext。這可能是我使用WIC程序集的人造物,但是(但我當然不使用Xaml和IUriContext)。
  • PresentationFramework提供Image類及其依賴性,如在the appropriate documentation
+0

它說沒有這樣的命名空間,請看編輯。 – Yoda

+0

@RobertKilar A downvote for not complying you made to your question _after_ I write my answer似乎有點不合理 – Rook

+0

@RobertKilar仍然沒有好處? – Rook

0

系統提到:視窗:控制命名空間(圖像類)需要PresentationFramework.dll作爲參考,和系統:視窗: :Media :: Imaging(用於BitmapSource類)命名空間需要PresentationCore.dll。

您是否在項目中包含這兩個參考?

相關問題