绘图应用程序 - 绘图无效不起作用

Drawing app - drawing void doesnt work

我正在用 Mic 制作一个应用程序。 Visual Studio,但我对这段代码有疑问。它应该是一个像画图一样的绘图应用程序。这部分代码正在制作线条/绘图,我有以下问题:

错误 C2664:'System::Drawing::Graphics ^System::Drawing::Graphics::FromImage(System::Drawing::Image ^)':无法将参数 1 从 'System::Drawing::Image' 转换为 'System::Drawing::Image ^' e:\programovanie\ikid\kreslenie\testing123l\testing123l\MyForm1.h 215 1 testing123l

IntelliSense: 无法使用给定的参数列表调用函数 "System::Windows::Forms::PictureBox::Image::set" 参数类型是:(System::Drawing::Bitmap) 对象类型是:System::Windows::Forms::PictureBox ^ e:\Programovanie\iKID\Kreslenie\testing123l\testing123l\MyForm1.h 218 4 testing123l

我对这种类型的 C++ 很陌生,直到现在我都在做一些简单的事情,例如 cin、cout、sort、文本游戏和类似的东西...

    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;
    }
}

您的问题是由于试图创建 "Image" 类型的对象引起的。图像 class 无法实例化,因为它是抽象的并且具有未实现的方法。

您可以使用 'reference type' 的句柄:Image^ iBitMapImage;(注意胡萝卜)。为了更好地理解如何使用图像 class 查看 MSDN 网站上的示例 https://msdn.microsoft.com/en-us/library/system.drawing.image(v=vs.110).aspx