您好,
我使用贵公司的MINI2440+T3.5的板子和OV9650摄像头,调试WINCE5.0下的摄像头程序,发现不能实现预览,抓拍的图像也不正确(有图像产生,好像是两帧图像在一起的),DeviceIoControl均没有报错,找了好久不知道什么原因,希望能指教一下。 另外,驱动是不是有问题,从抓拍的图像看图片是镜像的(就像照镜子一样,实际的摄像头应该是左手在右边的这种,提供的测试程序也是这种情况),不知道怎么改过来。
代码如下:
1.打开摄像头设备
m_held=INVALID_HANDLE_VALUE;
m_held=CreateFile(_T("CIS1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(m_held==INVALID_HANDLE_VALUE )
{
AfxMessageBox(_T("无法打开设备!请检查设备是否已被占用。"));
}
2.打开预览
BOOL ret;
CAMINFO sCam;
sCam.nDestHeight=320;
sCam.nDestWidth=240;
sCam.nZoomIndex=1;
ret = DeviceIoControl(m_held,CAM_IOCTL_IMAGE_CHANGE,NULL,NULL,&sCam,NULL,NULL,NULL);
if(!ret)
AfxMessageBox(_T("设置大小失败!"));
ret = DeviceIoControl(m_held,CAM_IOCTL_SAMSUNG_PREVIEW_START,NULL,NULL,NULL,NULL,NULL,NULL);
if(!ret)
AfxMessageBox(_T("启动预览失败!"));
ret = DeviceIoControl(m_held,CAM_IOCTL_MOVIE_START,NULL,NULL,NULL,NULL,NULL,NULL);
if(!ret)
AfxMessageBox(_T("播放失败!"));
3. 抓拍
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>640)
width=640;
if(height>480)
height=480;
ret=DeviceIoControl(m_held,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;
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;