COLORREF *m_Data;
CBitmap bm;
CDC *MemDc = new CDC;
int m_iWidth = pDoc->m_iWidth, m_iHeight = pDoc->m_iHeight;
pDC->SetBkMode(TRANSPARENT);//设置背景颜色为透明
m_Data = new COLORREF[m_iHeight * m_iWidth];//为颜色数据分配空间
//颜色空间赋值
for (int i = 0;i < m_iHeight;i++)
{
for (int j = 0;j < m_iWidth;j++)
{
m_Data[i * m_iWidth + j] = RGB((pDoc->TheImage8U->imageData[i * m_iStep + j]),(pDoc->TheImage8U->imageData[i * m_iStep + j]),(pDoc->TheImage8U->imageData[i * m_iStep + j]));
}
}
//创建bitmap
bm.CreateBitmap(m_iWidth,m_iHeight,1,32,m_Data);
//实现双缓冲,避免闪烁
MemDc->CreateCompatibleDC(pDC);
MemDc->SelectObject(&bm);
pDC->SetStretchBltMode(COLORONCOLOR);
pDC->StretchBlt(0,0,m_iWidth,m_iHeight,MemDc,0,0,m_iWidth,m_iHeight,SRCCOPY);
//删除已经分配的内存空间
ReleaseDC(MemDc);
delete MemDc;
bm.DeleteObject();
delete[] m_Data;
MFC图像显示
最新推荐文章于 2023-09-05 09:59:25 发布