如何将IplImage放置在PictureBox上?

3

有没有办法在picturebox中显示IplImage?

我不想保存图像并重新加载到picturebox中,因为我需要我的程序运行速度快。

我正在使用C++中的opencv 2.1。 我正在使用Visual Studio 2008工作。谢谢。

1个回答

3

这已经在这里讨论过:

IplImage* img=cvLoadImage("sample.jpg",3); // for example

HDC hdc = picturebox.GetDC()->m_hDC;
char m_chBmpBuf[2048];
BITMAPINFO *m_pBmpInfo =0;
m_pBmpInfo = (BITMAPINFO *)m_chBmpBuf;
m_pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
m_pBmpInfo->bmiHeader.biWidth = img->width;
m_pBmpInfo->bmiHeader.biHeight = -img->height;
m_pBmpInfo->bmiHeader.biBitCount= 24;

m_pBmpInfo->bmiHeader.biPlanes = 1;
m_pBmpInfo->bmiHeader.biCompression = BI_RGB;
m_pBmpInfo->bmiHeader.biSizeImage = 0;
m_pBmpInfo->bmiHeader.biXPelsPerMeter = 0;
m_pBmpInfo->bmiHeader.biYPelsPerMeter = 0;
m_pBmpInfo->bmiHeader.biClrUsed = 0;
m_pBmpInfo->bmiHeader.biClrImportant = 0;

StretchDIBits(hdc, 0, 0, img->width, img->height, 
                   0, 0, img->width, img->height, 
                   img->imageData, m_pBmpInfo,
                   DIB_RGB_COLORS, SRCCOPY);

抱歉,但它不起作用。HDC hdc = picturebox.GetDC()->m_hDC; 我无法在C++中这样做,我尝试了这种方式HANDLE handle = (HANDLE)this->PbBoxImg->Handle.ToPointer();//.ToInt32(); HWND hWnd=(HWND)&handle; 现在我没有错误,但是图片框中没有显示任何内容。HDC hdc1 = GetDC(hWnd); - andrea
我会在周末看一下。我现在没有Windows。 - karlphillip
1
我找到了解决方案:this->pictureBox1->Image=(gcnew System::Drawing::Bitmap(img->width,img->height,img->widthStep, System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)img->imageData)); 我不知道这是否是最好的解决方案,但它可以工作。仍然非常感谢你的帮助。 - andrea

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接