【问题标题】:Drawing app - drawing void doesnt work绘图应用程序 - 绘图无效
【发布时间】:2016-03-29 13:29:02
【问题描述】:

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

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

错误 C2664: 'System::Drawing::Graphics ^System::Drawing::Graphics::FromImage(System::Drawing::Image ^)' : 无法从 'System::Drawing::Image 转换参数 1 ' 到 '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、排序、文本游戏和类似的东西......

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

【问题讨论】:

    标签: c++ drawing


    【解决方案1】:

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

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

    【讨论】:

    • 好吧,我添加了胡萝卜,消除了一个错误...您不知道其他两个错误吗? :)
    • Graphics 也是一个抽象类,因此它与 Image 的问题相同 - 再次使用引用句柄。我不确定第二个,但似乎您正在尝试使用 Bitmap 对象,而您应该使用 Image^。也许您想使用 iBitMapImage?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多