---
title: "windows mobile上调用摄像头接口"
author: "mmdev"
date: "2008-09-04T15:37:00Z"
tags: []
slug: "windows-mobile"
draft: false
lastmod: "2008-09-04T15:37:00Z"
id: 1007211
url: "https://mmdev.iteye.com/blog/1007211"
---

使用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上没有统一摄像头标准，硬件厂商各做各的，只能跟硬件厂商询问调用方法。