2016-03-29 48 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