how to put an Iplimage on a picturebox?

早过忘川 提交于 2019-12-10 09:44:46

问题


Is there a way to show an IplImage in a picturebox?

I'd like to not save the image and reload it into the picturebox since I need my program to be fast.

I'm using opencv 2.1 in C++. I'm working with Visual Studio 2008. Thank you.


回答1:


This was already discussed here:

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);


来源:https://stackoverflow.com/questions/8805386/how-to-put-an-iplimage-on-a-picturebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!