2016-03-29 47 views
1

即時製作一個應用程序在麥克風。 Visual Studio,但我有這個代碼的問題。它應該是一個像繪畫一樣的繪畫應用程序。這部分代碼是製作線條/繪圖,我遇到以下問題:繪圖應用程序 - 繪製虛空不起作用

  • 「Graphics g = Graphics :: FromImage(iBitMapImage);」 - >

Error C2664:'System :: Drawing :: Graphics^System :: Drawing :: Graphics :: FromImage(System :: Drawing :: Image ^)':無法將參數1從'System: :繪圖::圖片」到 '系統::繪圖::圖片^' E:\ programovanie \ ikid \ kreslenie \ testing123l \ testing123l \ MyForm1.h 215 1 testing123l

  • 「pictureBox->圖像位圖=; 「 - >

智能感知:功能「系統:視窗:形式:圖片框::圖像::設爲」不能用給定的參數列表 參數類型被稱爲是:(系統::繪圖::位圖) 對象類型是:System :: Windows :: Forms :: PictureBox^e:\ Programovanie \ iKID \ Kreslenie \ testing123l \ testing123l \ MyForm1.h 218 4 testing123l

對於這種類型的C++我很新,現在我正在做一些簡單的事情,如cin,cout,排序,文字遊戲和類似的東西...

private: System::Void pictureBox_MouseMove(System::Object^ sender, S ystem::Windows::Forms::MouseEventArgs^ e) 
    { 
    if (e->Button == System::Windows::Forms::MouseButtons::Left) 
    { 
     Image ^iBitMapImage; 
     Graphics g = Graphics::FromImage(iBitMapImage); 
     g.DrawLine(Pens::Black, oldPosition, e->Location); 
     oldPosition = e->Location; 
     pictureBox->Image = bitmap; 
    } 
} 

回答

0

您的問題是由於嘗試創建「圖像」類型的對象而導致的。 Image類不能被實例化,因爲它是抽象的,並且具有未實現的方法。

您可以使用'引用類型'的句柄:Image^ iBitMapImage;(注意carot)。爲了更好地理解如何使用Image類,請查看MSDN網站上的例子https://msdn.microsoft.com/en-us/library/system.drawing.image(v=vs.110).aspx

+0

那麼我加了胡蘿蔔,其中一個錯誤就被消除了......你不知道另外兩個錯誤嗎? :) –

+0

圖形也是一個抽象類,所以它與圖像一樣的問題 - 再次使用引用的句柄。 我不確定第二個,但它似乎是你想使用一個位圖對象,你應該使用圖像^。也許你想使用iBitMapImage? – Moreira