编写wince+EVC+ov9650应用程序时遇到的问题
我在开发一个能够进行预览和拍照的应用程序,编译能够通过,可是在板子上跑的时候不能拿到图像数据。用DNW观察显示如下信息:
SENDING command id 0x8003 to CShexiangView target.
CAMERA: CIS_Open
CAM_IOCTL_SAMSUNG_CAM_PR
Data Abort: Thread=836a0ce0 Proc=80426ae0 'shexiang.exe'
AKY=00000401 PC=03fc3fbc(coredll.dll+0x00053fbc) RA=00011c94(shexiang.exe+0x00001c94) BVA=160e4000 FSR=00000007
请问我错在哪里?刚开始学习摄像头编程,希望能够详细指点。另外,我这样读摄像头的思想对吗?先用CreateFile打开摄像头,然后DeviceIoControl(m_hled,CAM_IOCTL_SAMSUNG_CAM_PR,NULL,NULL,(PBYTE)&image,NULL,NULL,NULL)获得存储图像的首地址,最后用memcpy把数据从摄像头缓冲区拷贝出来?谢谢指点!
程序如下:
void CShexiangView::OnYuLan()
{
// TODO: Add your command handler code here
HANDLE m_hled=CreateFile(_T("CIS1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
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,(BYTE *)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;
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;
}