mfc如何显示raw图像,打算把raw转成bmp的

gyk2009 2012-10-22 07:32:54
raw数据由单片机通过串口发送到PC上,黑白图像,一个像素用一个字节表示,现在串口采集数据部分都完成了。。。想请教下,接下去的图像显示方法
...全文
461 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
傻X 2012-10-28
  • 打赏
  • 举报
回复
找个DIB类库,网上很多的
gyk2009 2012-10-28
  • 打赏
  • 举报
回复
CRawdlg的类是怎么写的,获得hDIB之后,该怎么操作显示在图像控件里,刚接触这些东西,有些不懂
傻X 2012-10-22
  • 打赏
  • 举报
回复
试下这个,转换成Bitmap的



/*************************************************************************
*
* Function: ReadRAWFile (CFile&)
*
* Purpose: Reads in the specified RAW file into a global chunk of
* memory.
*
* Returns: A handle to a dib (hDIB) if successful.
* NULL if an error occurs.
*
* Comments: BITMAPFILEHEADER is stripped off of the DIB.
* Everything from the end of the BITMAPFILEHEADER structure
* on is returned in the global memory handle.
*
**************************************************************************/
HDIB ReadRAWFile(CFile& file)
{
double min,max;
int width,height;

CRawdlg dlg;
if (dlg.DoModal() != IDOK) return FALSE;
width=dlg.m_width;
height=dlg.m_height;


//Allocate memory for the image
DWORD dwImageSize = width*height*12;// 12=DIBChannels
BYTE* pImageData = new BYTE[dwImageSize];

file.Read(pImageData,dwImageSize);


// Setup the DIB with the correct details
BITMAPINFO bmi;
BITMAPINFOHEADER& bih = bmi.bmiHeader;
ZeroMemory(&bih, sizeof(BITMAPINFOHEADER));
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biWidth = width;
bih.biHeight= height;
bih.biCompression = BI_RGB;
bih.biPlanes = 1;
bih.biBitCount = 24;

// Allocate memory for DIB
DWORD dwBmpBitsSize = WIDTHBYTES(width*24)*height;
HDIB hDIB = (HDIB) ::GlobalAlloc(GHND, bih.biSize + dwBmpBitsSize);
if (hDIB == 0)
{
TRACE(_T("Could not allocate memory for the DIB while loading from file!\n"));
delete [] pImageData;
return NULL;
}

LPSTR pDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
if (pDIB == 0)
{
TRACE(_T("Could not lock memory for the DIB while loading from file!\n"));
delete [] pImageData;
return NULL;
}

//Copy over the header to the DIB
CopyMemory(pDIB, &bmi.bmiHeader, bih.biSize);

//Copy the DIB bits from the user buffer into the DIB
BYTE* pBmp = (BYTE*) (pDIB + bih.biSize);
for (int j=0; j <height; j++)
{
int nDepthInOffset = j*width*3;
int nDepthOutOffset = (height-j-1)*WIDTHBYTES(width*24);
for (int i=0; i <width; i++)
{
int nInOffset = nDepthInOffset + i*3;
int nOutOffset = nDepthOutOffset + i*3;
pBmp[nOutOffset] = pImageData[nInOffset];
pBmp[nOutOffset+1] = pImageData[nInOffset+1];
pBmp[nOutOffset+2] = pImageData[nInOffset+2];
}
}

//Delete the memory used to load the jpeg prior to transfering to the DIB
delete [] pImageData;

::GlobalUnlock((HGLOBAL) hDIB);
return hDIB;

}

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧