[英]Marshal::copy with CvMat
我需要使用c ++ / cli将图像发送到字节数组中。 该图像最初为Iplimage格式。
int img_sz1 = img1->width * img1->height * img1->nChannels;
array <Byte>^ hh1 = gcnew array<Byte> (img_sz1);
Marshal::Copy( (IntPtr)img->imageData, hh1, 0, img_sz1 );
而且工作正常。
我添加了编码步骤以jpeg格式发送
CvMat* buf1 = cvEncodeImage(".jpeg", img1, jpeg_params);
img_sz1=buf1->width*buf1->height
Marshal::Copy( (IntPtr)buf1, hh1, 0, img_sz1 );
现在它可以正常编译,但在marshal:copy行给了我错误
An unhandled exception of type 'System.AccessViolationException' occurred in
mscorlib.dll. Additional information: Attempted to read or write protected memory.
任何帮助都非常感谢。
cvEncodeImage
的返回是一个单行矩阵,其中包含编码的图像数据。 您现在要复制的是结构本身,例如width字段,height字段等。我相信您需要从buf1->data
复制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.