错误 C2440:无法将"系统::D rawing::位图"转换为"系统::对象"
Error C2440 : cannot cast 'System::Drawing::Bitmap' into 'System::Object'
我最近开始使用OpenCV,努力将基于它的插件集成到已经存在的项目中。 这个使用System::D rawing::Bitmap来管理图像和一个System::EventArgs衍生物(不确定这个词),其中包含一个用于在插件之间传输数据的System::Object元素。
OpenCV 在C++我必须相应地编程我的插件,但多亏了 CLR(不太确定),我的新 c++ 类可以继承我的 C# "插件"接口。
这个插件非常简单,将 cv::Mat 转换为位图,然后将其转换为之前引用的数据对象并调用事件。
但它给了我错误 C2440 无法从系统::D rawing::位图转换为系统::对象。
我在 C# 中将位图转换为对象没有任何问题,但现在我C++了,这不再有效。
这怎么可能?我的意思是.Net的要点是,无论我是C#还是C++,Bitmap的继承都是相同的,对吗?
也许我没有完全掌握 clr 的事情以及它是如何工作的。 无论如何,提前感谢您的帮助。
.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:SIMONPluginCVPluginCVMat2Bitmap.cpp 16 1 PluginCV
PC 重新启动可以解决问题。 不知道是什么原因导致这不起作用,因为位图继承了对象......
无论如何,告别。
相关文章:
- C / C++ 移位/偏移/向左或向右移动位图?
- 如何在快板的屏幕中显示子位图的绘制?
- CreateDIBSection为同一图像返回不一致的位图位值
- C++ 位图中的 ttc 字体
- 使用 GDI+ 旋转位图,然后转换为 HDC
- 难以从 CImageList 设置菜单项位图
- 如何将位图拉伸到父面板(wxWidgets 自定义)
- 如何使用 freetype2 访问单色位图中的像素状态
- 将位图 (bmp) 转换为具有透明度的 png (Windows c++)
- 安卓工作室 |CPP 文件错误错误: 位图库中对"AndroidBitmap_unlockPixels"的未定义引用
- 位图到垫子/2D 数组
- Gdiplus位图没有Alpha通道
- 如何从路径字符串加载Gdiplus::位图
- 在C++中使用Gdiplus创建透明位图
- 用C++压缩内存中的位图
- C++gdi::内存中的位图到PNG图像
- LoadImage 函数不适用于 ImageMagick 创建的位图图像
- (位图)LoadImage() 返回 NULL,GetLastError() 返回 0
- 错误 C2440:无法将"系统::D rawing::位图"转换为"系统::对象"
- 系统::绘图::位图到无符号字符*