错误C2440:无法将"System :: Drawing :: Bitmap"转换为"System :: Object" [英] Error C2440 : cannot cast 'System::Drawing::Bitmap' into 'System::Object'

查看:177
本文介绍了错误C2440:无法将"System :: Drawing :: Bitmap"转换为"System :: Object"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始使用OpenCV,旨在将基于OpenCV的插件集成到现有项目中. 该代码使用System :: Drawing :: Bitmap来管理图像,并使用System :: EventArgs派生词(不确定该词),该派生词包含用于在插件之间传输数据的System :: Object元素.

I recently started tu use OpenCV in an effort to integrate plugins based on it to an already existing project. This one uses System::Drawing::Bitmap to manage images and a System::EventArgs derivative (not sure about that word) containing a System::Object element used to transfer data between plugins.

在C ++中使用OpenCV的方法,我必须对插件进行相应的编程,但是由于CLR(对此不太确定),我的新c ++类可以继承我的C#插件"接口.

OpenCV beeing in C++ I have to program my plugin accordingly but thanks to CLR (not very sure about that one) my new c++ class can inherit my C# "Plugin" interface.

这个插件非常简单,将cv :: Mat转换为位图,然后将其转换为先前引用的数据对象并调用事件.

This one plugin is pretty simple, converting cv::Mat to a Bitmap then casting it into the Data Object previously cited and invoking an event.

但这给了我错误C2440无法从System :: Drawing :: Bitmap投射到System :: Object.

But it's giving me error C2440 cannot cast from System::Drawing::Bitmap to System::Object.

我在用C#将位图转换为对象时没有任何问题,但是现在我在C ++中,这不再起作用了.

I didnt have any problem casting a Bitmap to an Object in C# but now that i'm in C++, this does not work anymore.

那怎么可能?我的意思是.Net的要点是无论我在C#还是C ++中,位图的继承都是相同的?

How's that even possible ? I mean the point of .Net is that Bitmap's inheritences are the same whether i'm in C# or C++ right ?

也许我没有完全掌握clr的内容及其工作原理. 无论如何,请先感谢您的帮助.

Maybe i didnt fully grasp the clr thing and how it works. Anyway, thanks in advance for your help.

.h文件:

namespace PluginCV 
{
    public ref class Mat2Bitmap : public InterfacePlugin::IPlugin
    {
    private:
        bool _isReady;
        System::EventHandler^ evt;
        System::Drawing::Bitmap^ Convert(cv::Mat img);
        cv::Mat* img;

    public:
        virtual void __clrcall Start(void) sealed;
        virtual void __clrcall Stop(void) sealed;
        virtual void __clrcall Handle(Object ^ obj, EventArgs ^ args) sealed;
        virtual void __clrcall InitWithNetwork(Object^ obj, int port) sealed;

        virtual property EventHandler^ DoneEvent
        {
            void set (EventHandler^ e) sealed { evt = e; };
            EventHandler^ get(void) sealed { return evt; };
        }

        virtual property bool isReady
        {
            void set (bool b) sealed { _isReady = b; };
            bool get(void) sealed { return _isReady; };
        }
    };
}

.cpp:

#include "Stdafx.h"

//#include "PluginCV.h"
#include "MatEventArg.h"

void PluginCV::Mat2Bitmap::Stop(void)
{

}

 void PluginCV::Mat2Bitmap::Start(void) 
{
     System::Drawing::Bitmap Bmp = Convert(*img);

     DATAMODEL::BBEventArgs bb;
     bb.Data = (System::Object)Bmp;
}

 System::Drawing::Bitmap^ PluginCV::Mat2Bitmap::Convert(cv::Mat img)
 {
     cv::Size s = img.size();
     System::Drawing::Bitmap^ bmp = gcnew System::Drawing::Bitmap(s.width, s.height, img.step1(), System::Drawing::Imaging::PixelFormat::Format24bppRgb, (System::IntPtr)img.data);

     return bmp;
 }

void PluginCV::Mat2Bitmap::Handle(Object^ obj, EventArgs^ args)
{
    PluginCV::MatEventArg^ e = (PluginCV::MatEventArg^)args;

    e->img->copyTo(*img);

    Start();
}

void PluginCV::Mat2Bitmap::InitWithNetwork(Object^ obj, int port)
{

}

错误代码(法语):

Erreur  1   error C2440: 'cast de type' : impossible de convertir de 'System::Drawing::Bitmap' en 'System::Object'  C:\SIMON\PluginCV\PluginCV\Mat2Bitmap.cpp   16  1   PluginCV

推荐答案

PC重新启动可以解决问题. 自从Bitmap继承Object以来,不知道是什么原因导致此方法无法正常工作.

A PC reboot did the trick. No idea whatsoever what could have caused this to not work since Bitmap inherits Object...

反正告别.

这篇关于错误C2440:无法将"System :: Drawing :: Bitmap"转换为"System :: Object"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆