在mobile上调用SHCameraCapture接口进行拍照
来源:互联网 发布:3g软件培训班 编辑:程序博客网 时间:2024/05/03 05:59
在mobile上调用SHCameraCapture接口进行拍照 收藏
本文所要讲的是使用SHCameraCapture接口可以调出照相机进行拍照、摄像,并得到图片或视频文件的路径。
以下代码进行拍照:
- SHCAMERACAPTURE shcc;
- ZeroMemory(&shcc, sizeof(shcc));
- shcc.cbSize = sizeof(shcc);
- shcc.hwndOwner = NULL;
- shcc.pszInitialDir = NULL;
- shcc.pszDefaultFileName = NULL;
- shcc.pszTitle = NULL;
- shcc.StillQuality = CAMERACAPTURE_STILLQUALITY_DEFAULT;
- shcc.VideoTypes = CAMERACAPTURE_VIDEOTYPE_ALL;
- shcc.nResolutionWidth = 0;
- shcc.nResolutionHeight = 0;
- shcc.nVideoTimeLimit = 0;
- shcc.Mode = CAMERACAPTURE_MODE_STILL;
- HRESULT hReturn = SHCameraCapture(&shcc);
如果hReturn为S_OK,则表示拍照成功,shcc.szFile即为文件名称(包含路径)。shcc.pszInitialDir和shcc.pszDefaultFileName可以设置保存路径和默认文件名。shcc.hwndOwner如果使用了不同的窗体,可能会有问题。
如果要进行摄像,有些参数需进行调整,如下
shcc.StillQuality = CAMERACAPTURE_STILLQUALITY_NORMAL;
shcc.VideoTypes = CAMERACAPTURE_VIDEOTYPE_STANDARD;
shcc.nResolutionWidth = 640;
shcc.nResolutionHeight = 480;
shcc.Mode = CAMERACAPTURE_MODE_VIDEOWITHAUDIO;
这些参数涉及到几个枚举变量,我们来看看:
typedef enum {
CAMERACAPTURE_MODE_STILL = 0,
CAMERACAPTURE_MODE_VIDEOONLY,
CAMERACAPTURE_MODE_VIDEOWITHAUDIO,
} CAMERACAPTURE_MODE;
CAMERACAPTURE_MODE_STILL对应照片,CAMERACAPTURE_MODE_VIDEOONLY对应无声视频,CAMERACAPTURE_MODE_VIDEOWITHAUDIO对应有声视频。
typedef enum {
CAMERACAPTURE_STILLQUALITY_DEFAULT = 0,
CAMERACAPTURE_STILLQUALITY_LOW,
CAMERACAPTURE_STILLQUALITY_NORMAL,
CAMERACAPTURE_STILLQUALITY_HIGH,
} CAMERACAPTURE_STILLQUALITY;
对应图片和视频清晰度。
typedef enum {
CAMERACAPTURE_VIDEOTYPE_ALL = 0xFFFF,
CAMERACAPTURE_VIDEOTYPE_STANDARD = 1,
CAMERACAPTURE_VIDEOTYPE_MESSAGING = 2,
} CAMERACAPTURE_VIDEOTYPES;
CAMERACAPTURE_VIDEOTYPE_ALL对应照片,CAMERACAPTURE_VIDEOTYPE_STANDARD对应WMV视频,CAMERACAPTURE_VIDEOTYPE_MESSAGING对应MMS视频。当使用后两个值时,shcc的nResolutionWidth和nResolutionHeight成员均不能为零。一般是640x480。
很遗憾,这个接口只能在WM5.0以上使用。WM2003上没有统一摄像头标准,硬件厂商各做各的,只能跟硬件厂商询问调用方法。
下面给出两个函数代码:
- 1.拍照
- LPCTSTR CphotoDlg::StartTakePic(void)
- {
- HRESULT hReturn;
- SHCAMERACAPTURE shcc;
- CString str = GetCurWorkingDir();
- // Specify the arguments of SHCAMERACAPTURE
- ZeroMemory( &shcc, sizeof( shcc ) );
- shcc.cbSize = sizeof( shcc );
- //shcc.hwndOwner = m_hWnd;
- shcc.hwndOwner = NULL;
- shcc.pszDefaultFileName = L"photo.jpg";
- shcc.pszTitle = NULL;
- shcc.pszInitialDir = str;
- shcc.StillQuality = CAMERACAPTURE_STILLQUALITY_DEFAULT;
- shcc.VideoTypes = CAMERACAPTURE_VIDEOTYPE_ALL;
- shcc.nResolutionWidth = 0;
- shcc.nResolutionHeight = 0;
- shcc.nVideoTimeLimit = 0;
- shcc.Mode = CAMERACAPTURE_MODE_STILL;
- //Call SHCameraCapture() function
- hReturn = SHCameraCapture( &shcc );
- //Check the return codes of the SHCameraCapture() function
- switch (hReturn)
- {
- case S_OK:
- AfxMessageBox( L"成功拍照" );
- return (LPCTSTR)shcc.szFile;
- case S_FALSE:
- //The user canceled the Camera Capture dialog box.
- AfxMessageBox( L"没有拍照" );
- break;
- case E_INVALIDARG:
- break;
- case E_OUTOFMEMORY:
- {
- AfxMessageBox( L"Out of Memory" );
- }
- break;
- default:
- break;
- }
- return NULL;
- }
- 2.摄像(默认保存的是mp4格式)
- LPCTSTR CphotoDlg::StartRecord(void)
- {
- HRESULT hReturn;
- SHCAMERACAPTURE shcc;
- CString str = GetCurWorkingDir();
- //Specify the arguments of SHCAMERACAPTURE
- ZeroMemory( &shcc, sizeof( shcc ) );
- shcc.cbSize = sizeof( shcc );
- shcc.hwndOwner = m_hWnd;
- shcc.pszInitialDir = str;
- shcc.pszDefaultFileName = TEXT( "video.3gp" );
- shcc.pszTitle = NULL;
- shcc.StillQuality = CAMERACAPTURE_STILLQUALITY_HIGH;
- shcc.VideoTypes = CAMERACAPTURE_VIDEOTYPE_STANDARD;
- shcc.nResolutionWidth = 640; //这两个参数如果设置非零,模拟器是调不出来的,但是真机上是没得问题的。
- shcc.nResolutionHeight = 480;
- shcc.nVideoTimeLimit = 0; //0表示无限制录像时间
- shcc.Mode = CAMERACAPTURE_MODE_VIDEOWITHAUDIO;
- //Call SHCameraCapture() function
- hReturn = SHCameraCapture( &shcc );
- //Check the return codes of the SHCameraCapture() function
- switch (hReturn)
- {
- case S_OK:
- AfxMessageBox( L"成功录像" );
- return (LPCTSTR)shcc.szFile;
- case S_FALSE:
- //The user canceled the Camera Capture dialog box.
- AfxMessageBox( L"没有录像" );
- break;
- case E_INVALIDARG:
- AfxMessageBox( L"E_INVALIDARG" );
- break;
- case E_OUTOFMEMORY:
- AfxMessageBox( L"Out of Memory" );
- break;
- default:
- break;
- }
- return NULL;
- }
- 在mobile上调用SHCameraCapture接口进行拍照
- 在mobile上调用SHCameraCapture接口进行拍照
- 在mobile上调用SHCameraCapture接口进行拍照
- 如何在mobile手机上,调用拍照和录音功能?
- windows mobile上调用摄像头接口
- windows mobile上调用摄像头接口
- windows mobile上调用摄像头接口
- windows mobile上调用摄像头接口
- Android调用系统摄像头拍照并显示在ImageView上
- Windows Mobile 调用摄像头拍照录像
- 调用系统相机进行拍照
- 调用系统摄像头拍照,对拍照后的图片进行裁剪和压缩处理,并显示在imageview上面
- Air进行mobile的拍照、相册图片打开、写入相关
- 使用opencv2在qt界面上进行摄像头采集以及简单的拍照功能
- 使用Java调用摄像头进行拍照源码
- SurfaceView调用camera进行显示与拍照
- 调用系统相机进行拍照并保存
- HTML 5调用摄像头并进行拍照
- 为什么婚戒要戴在无名指上
- ipad的电子书的确够炫
- "强单“ 或者 抢单 更合适
- 关于WSDL
- s数据库设计中的14个技巧
- 在mobile上调用SHCameraCapture接口进行拍照
- 事件监听处理小框架
- 谈谈怎样选择域名
- TotalActivities,TotalPossibleActivities,NotApplicableActivities的计算方法
- Tomcat6.0数据源配置
- 个人开公司的流程,以后用得着
- 顺序链表,动态数组实现
- 以色列禁止进口苹果iPad:担心无线网络超载
- excel2007 公式自动计算