【问题标题】:how to put an Iplimage on a picturebox?如何将 Iplimage 放在图片框上?
【发布时间】:2012-02-06 23:44:36
【问题描述】:

有没有办法在图片框中显示 IplImage?

我不想保存图像并将其重新加载到图片框中,因为我需要我的程序快速。

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

【问题讨论】:

    标签: c++ visual-studio-2008 opencv picturebox


    【解决方案1】:

    这已经讨论过了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);
    

    【讨论】:

    • 对不起,它不起作用.. HDC hdc = picturebox.GetDC()->m_hDC;我在c++中不能这样做,我试过这样 HANDLE handle = (HANDLE)this->PbBoxImg->Handle.ToPointer();//.ToInt32(); HWND hWnd=(HWND)&句柄;现在我没有收到任何错误,但图片框中没有显示任何内容 HDC hdc1 = GetDC(hWnd);
    • 我周末去看看。我现在没有 Windows。
    • 我找到了解决方案:this->pictureBox1->Image=(gcnew System::Drawing::Bitmap(img->width,img->height,img->widthStep, System::Drawing ::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)img->imageData));不知道它是否是最好的,但它有效。仍然非常感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    相关资源
    最近更新 更多