我正在使用此代码将 IplImage 放入图片框中,注释部分不起作用,因此我尝试使用代码的前 3 行,但第三行在编译时返回 3 个错误:
1>UIThread.obj:错误LNK2028:在函数“private: void clrcall UIThread : :Form1::BtnAcquire_Click(类 System::Object ^,类 System::EventArgs ^)" (?BtnAcquire_Click@Form1@UIThread@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) 1>UIThread.obj:错误 LNK2019:无法解析的外部符号“extern”C“struct HDC * stdcall GetDC(struct HWND *)”(?GetDC@@$$J14YGPAUHDC_ @@PAUHWND_@@@Z) 在函数“private: void __clrcall UIThread::Form1::BtnAcquire_Click(class System::Object ^,class System::EventArgs ^)”中引用 (?BtnAcquire_Click@Form1@UIThread@@$$FA$ AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z) 1>C:\Users\Andrea Parola\Documents\Visual Studio 2008\Projects\UIThread\Debug\UIThread.exe : 致命错误 LNK1120: 2 unresolved externals
那么如何将 HWND 转换为 HDC?
HANDLE handle = (HANDLE)this->PbBoxImg->Handle.ToInt32();
HWND hWnd=*(HWND*)&handle;
HDC hdc = GetDC(hWnd);
//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);