15,979
社区成员
发帖
与我相关
我的任务
分享
void CameraDisplay_bitmap(BYTE * pbyRGB24, tDSFrameInfo * frameInfo)
{
CImage*image_show = new CImage;
image_show->Create(frameInfo->uiWidth, frameInfo->uiHeight, 24, 0);
for (unsigned int y = 0; y < frameInfo->uiHeight; y++)
{
BYTE *image_byte = (BYTE*)image_show->GetPixelAddress(0, y);
memcpy(image_byte, pbyRGB24 + (frameInfo->uiHeight - y - 1)*frameInfo->uiWidth * 3, frameInfo->uiWidth * 3);
}
HBITMAP hbmp = (HBITMAP)image_show->Detach();
CBitmap* bitmap = new CBitmap;//创建位图
bitmap->DeleteObject();
bitmap->Attach(hbmp);
CDC dcMem;//兼容的内存DC
dcMem.CreateCompatibleDC(cDC);
BITMAP bmp;
bitmap->GetBitmap(&bmp);
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject(&bitmap);
CRect rect_bit;//控件位置尺寸(0,0,w,h)
cDC->GetWindow()->GetClientRect(&rect_bit);
cDC->SetStretchBltMode(STRETCH_HALFTONE);//设置伸展模式:半色调
cDC->StretchBlt(0, 0, rect_bit.Width(), rect_bit.Height(), &dcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
dcMem.SelectObject(pOldBitmap);
VERIFY(bitmap->DeleteObject());
VERIFY(dcMem.DeleteDC());
delete bitmap;
delete image_show;
}
void CameraDisplay_bitmap(BYTE * pbyRGB24, tDSFrameInfo * frameInfo)
{
CImage*image_show = new CImage;
image_show->Create(frameInfo->uiWidth, frameInfo->uiHeight, 24, 0);
for (unsigned int y = 0; y < frameInfo->uiHeight; y++)
{
BYTE *image_byte = (BYTE*)image_show->GetPixelAddress(0, y);
memcpy(image_byte, pbyRGB24 + (frameInfo->uiHeight - y - 1)*frameInfo->uiWidth * 3, frameInfo->uiWidth * 3);
}
CWnd* wnd = cDC->GetWindow();
CRect rect;
GetClientRect(wnd->m_hWnd, rect);
SetStretchBltMode(cDC->m_hDC, STRETCH_HALFTONE);
image_show->StretchBlt(cDC->m_hDC, rect, SRCCOPY);
image_show->Draw(cDC->m_hDC, rect);
delete image_show;
}
void CameraDisplay_bitmap(BYTE * pbyRGB24, tDSFrameInfo * frameInfo)
{
CImage*image_show = new CImage;//CImage数据加载
image_show->Create(frameInfo->uiWidth, frameInfo->uiHeight, 24, 0);
for (unsigned int y = 0; y < frameInfo->uiHeight; y++)
{
BYTE *image_byte = (BYTE*)image_show->GetPixelAddress(0, y);
memcpy(image_byte, pbyRGB24 + (frameInfo->uiHeight - y - 1)*frameInfo->uiWidth * 3, frameInfo->uiWidth * 3);
}
CDC dcMem;//内存DC
dcMem.CreateCompatibleDC(cDC);
ASSERT(NULL != dcMem.GetSafeHdc());
CBitmap bitmap;
HBITMAP hbmp = (HBITMAP)image_show->Detach();//CBitmap数据加载
bitmap.DeleteObject();
bitmap.Attach(hbmp);
ASSERT(NULL != bitmap.GetSafeHandle());
BITMAP bmp;
bitmap.GetBitmap(&bmp);
CRect rect;
cDC->GetWindow()->GetClientRect(&rect);
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject(&bitmap);
dcMem.SetBkMode(TRANSPARENT);//输出格式
dcMem.SetTextColor(RGB(255, 0, 0));
SelectObject(dcMem.m_hDC, font);
dcMem.DrawText("帧 率:", CRect(20, 50, 550, 130), DT_CENTER | DT_VCENTER | DT_SINGLELINE);
dcMem.DrawText(str_rate, CRect(570, 50, 800, 130), DT_CENTER | DT_VCENTER | DT_SINGLELINE);
dcMem.DrawText("CPU占用率:", CRect(20, 140, 550, 220), DT_CENTER | DT_VCENTER | DT_SINGLELINE);
dcMem.DrawText(str_cpu, CRect(570, 140, 800, 220), DT_CENTER | DT_VCENTER | DT_SINGLELINE);
cDC->SetStretchBltMode(STRETCH_HALFTONE);//拉伸模式
cDC->StretchBlt(rect.left, rect.top, rect.Width(), rect.Height(), &dcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
dcMem.SelectObject(pOldBitmap);
VERIFY(bitmap.DeleteObject());
VERIFY(dcMem.DeleteDC());
}
void CameraDisplay_bitmap(BYTE * pbyRGB24, tDSFrameInfo * frameInfo)
{
CImage*image_show = new CImage;
image_show->Create(frameInfo->uiWidth, frameInfo->uiHeight, 24, 0);
for (unsigned int y = 0; y < frameInfo->uiHeight; y++)
{
BYTE *image_byte = (BYTE*)image_show->GetPixelAddress(0, y);
memcpy(image_byte, pbyRGB24 + (frameInfo->uiHeight - y - 1)*frameInfo->uiWidth * 3, frameInfo->uiWidth * 3);
}
HBITMAP hbmp = (HBITMAP)image_show->Detach();
CBitmap* bitmap = new CBitmap;//创建位图
bitmap->DeleteObject();
bitmap->Attach(hbmp);
HWND hWND = GetDlgItem(afx_m_hWnd, IDC_PIC);//其中afx_m_hWnd为对话框句柄,afx_m_hWnd = this->m_hWnd
HDC hDC = GetDC(hWND);
CDC*pDC = new CDC;
pDC->Attach(hDC);
CDC dcMem;//兼容的内存DC
dcMem.CreateCompatibleDC(pDC);
BITMAP bmp;
bitmap->GetBitmap(&bmp);
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject(&bitmap);
CRect rect_bit;//控件位置尺寸(0,0,w,h)
pDC->GetWindow()->GetClientRect(&rect_bit);
pDC->SetStretchBltMode(STRETCH_HALFTONE);//设置伸展模式:半色调
pDC->StretchBlt(0, 0, rect_bit.Width(), rect_bit.Height(), &dcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
dcMem.SelectObject(pOldBitmap);
VERIFY(bitmap->DeleteObject());
VERIFY(dcMem.DeleteDC());
ReleaseDC(hWND, hDC);
delete bitmap;
delete image_show;
delete pDC;
}