绘图应用程序-绘图无效



im在Mic中制作应用程序。Visual Studio,但我对此代码有问题。它应该是一个像绘画一样的绘画应用程序。这部分代码正在进行划线/绘图,我对以下内容有问题:

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

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

  • "pictureBox->Image=位图;"->

IntelliSense:无法使用给定的参数列表调用函数"System::Windows::Forms::PictureBox::Image::set"参数类型为:(系统::绘图::位图)对象类型为:System::Windows::Forms::PictureBox^e:\Programovanie\iKID\Kreslenie\testing123l\testing12.3l\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;
    }
}

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

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

相关内容

最新更新