|
WinCE下Camera能正常显示影像,拍照时花屏
[复制链接]
三星2440 WinCE下的CameraTest测试程序在我的开发板上能正常显示影像,拍照保存下来的BMP图是花屏。不知道从哪里入手,请大家指教。贴一下拍照部分的代码。
void CCameratestDlg::OnButton3()
{
// TODO: Add your control notification handler code here
PINGPONG_PR image;
WORD width=GetSystemMetrics(SM_CXSCREEN);
WORD height=GetSystemMetrics(SM_CYSCREEN);
BOOL ret;
BYTE* DDBdata=new BYTE[width*height*2];
BYTE* DIBdata;
if(width>320)
width=320;
if(height>240)
height=240;
ret=DeviceIoControl(m_hled,CAM_IOCTL_SAMSUNG_CAM_PR,NULL,NULL,(PBYTE)&image,NULL,NULL,NULL);
if(!ret)
AfxMessageBox(_T("读取图片失败!"));
else
{
SetKMode(TRUE);
memcpy(DDBdata,(void *)image.rgb_address,width*height*2);
SetKMode(FALSE);
CBitmap bitmap;
HBITMAP dstBmp;
bitmap.CreateBitmap(width,height,1,16,DDBdata);
HDC hdcSrc = CreateCompatibleDC(NULL);
HDC hdcDst = CreateCompatibleDC(NULL);
BITMAPINFOHEADER bih = {0};//位图信息头
bih.biBitCount = 16;//每个像素字节大小
bih.biCompression = BI_RGB;
bih.biHeight = height;//高度
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = 0;// width*height*2;//图像数据大小
bih.biWidth = width;//宽度
BITMAPFILEHEADER bfh = {0};//位图文件头
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//到位图数据的偏移量
bfh.bfSize = bfh.bfOffBits + width*height*2;//文件总的大小
bfh.bfType = (WORD)0x4d42;
BITMAPINFO bi={0};
bi.bmiHeader=bih;
RETAILMSG(1,(TEXT("VideoWidth = %d, VideoHeight = %d\r\n"), width, height));
dstBmp=CreateDIBSection(hdcDst, (BITMAPINFO*)&bi, DIB_RGB_COLORS, (void **)&DIBdata, NULL, 0);
SelectObject(hdcDst, dstBmp);
SelectObject(hdcSrc, bitmap);
BitBlt(hdcDst, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY);
CFile file(_T("image.bmp"),CFile::modeCreate|CFile::modeReadWrite);
file.Write(&bfh,sizeof(bfh));
file.Write(&bih,sizeof(bih));
file.Write(DIBdata,width*height*2);
file.Close();
}
delete []DDBdata;
}
|
|