BITMAPINFO *m_pBMI1; m_pBMI1= new BITMAPINFO;//自定義的BMP文件信息結構,,用于后面的圖像顯示 ZeroMemory(m_pBMI1, sizeof(BITMAPINFO)); m_pBMI1->bmiHeader.biBitCount=24; m_pBMI1->bmiHeader.biClrImportant=0; m_pBMI1->bmiHeader.biClrUsed=0; m_pBMI1->bmiHeader.biCompression=BI_RGB; m_pBMI1->bmiHeader.biHeight=iHeight; m_pBMI1->bmiHeader.biPlanes=1; m_pBMI1->bmiHeader.biSize=40; m_pBMI1->bmiHeader.biSizeImage=WIDTHBYTES(iWidth*8)*iHeight*3; m_pBMI1->bmiHeader.biWidth=iWidth; m_pBMI1->bmiHeader.biXPelsPerMeter=0; m_pBMI1->bmiHeader.biYPelsPerMeter=0; CRect rect; CWnd *pWnd=GetDlgItem(IDC_STATIC_VIDEO); pWnd->GetClientRect(&rect); int rw=rect.right-rect.left; int rh=rect.bottom-rect.top; CDC *pdc=GetDlgItem(IDC_STATIC_VIDEO)->GetDC(); HDC hdc=pdc->GetSafeHdc(); BYTE *pData1=NULL; HANDLE hdib=(HANDLE)::GlobalAlloc(GMEM_FIXED,WIDTHBYTES(iWidth*8)*3*iHeight); pData1=(BYTE*)::GlobalLock((HGLOBAL)hdib); ///m_recvBuf中的數據拷貝到pData1中,考慮到對齊 int nstride; nstride=WIDTHBYTES(iWidth*8)*3; for(int i=0;i<iHeight;i++){ for(int j=0;j<iWidth;j++){ //m_recvBuf為RGB數據 *(pData1+i*nstride+j*3)=*(m_recvBuf+i*iWidth*3+j*3); *(pData1+i*nstride+j*3+1)=*(m_recvBuf+i*iWidth*3+j*3+1); *(pData1+i*nstride+j*3+2)=*(m_recvBuf+i*iWidth*3+j*3+2); } } pdc->SetBkMode(TRANSPARENT); //顯示真彩色圖像 StretchDIBits(hdc,0,0,rw,rh,0,0,iWidth,iHeight,pData1,m_pBMI1,DIB_RGB_COLORS,SRCCOPY); GlobalUnlock((HGLOBAL)hdib); ReleaseDC(pdc); delete pData1; delete m_pBMI1; // |
|
來自: 昵稱12110172 > 《C 學習》