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