转换系统::图::位图^到:: MAT [英] Converting System::Drawing::Bitmap^ to ::MAT

查看:334
本文介绍了转换系统::图::位图^到:: MAT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C ++ / CLI中将图片框中的图片转换为 :: MAT

How converting image from picturebox to ::MAT in C++/CLI?

谢谢

推荐答案

您需要 cast 将Drawing.Image导入 位图 (假设图像真的是位图)。

然后锁定 System.Drawing.Bitmap ,并使用BitmapData的Scan0属性访问内部缓冲区。

You need to cast the Drawing.Image into a Bitmap (assuming that the image REALLY IS a bitmap).
Then lock the System.Drawing.Bitmap, and use the Scan0 property of the BitmapData to access the inner buffer.

System::Drawing::Bitmap ^ bitmapFrame = safe_cast< System::Drawing::Bitmap ^ >(pictureBox1->Image);

BitmapData^ bmpData = bitmapFrame->LockBits(gcnew Rectangle(0, 0, bitmapFrame->Width, bitmapFrame->Height), System::Drawing::Imaging::ImageLockMode::ReadWrite, 
            bitmapFrame->Format);
try
{    
    void* data = bmpData.Scan0;

    //use the data in the ::Mat constructor.
}
finally { bitmapFrame->UnlockBits(bmpData); }//Remember to unlock!!!

这篇关于转换系统::图::位图^到:: MAT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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