本节将介绍如何使用照相设备进行拍照,并保存照片。
1. MediaCapture
winRT中使用MediaCapture类进型拍照和录制视频相关操作。具体该类的介绍参考https://msdn.microsoft.com/zh-cn/library/windows/apps/windows.media.capture.mediacapture.aspx。通过Mediacapture获取照相资源,由于照相资源在系统中是唯一的,所以我们必须在退出拍照页面和应用挂起时释放资源,否则在应用挂起时开启别的应用(如照相机)会出现资源被占用的情况而死机。具体流程如下:
1) 一般手机都有前置, 后置摄像头,具体使用哪个摄像头会根据应用的要求而不相同。所以首先,我们要根据需求来决定使用哪个摄像头. 如获取后置摄像头:
task<DeviceInformation^> PhotoCapturePage::GetCamera(Windows::Devices::Enumeration::Panel camera)
{
return create_task(DeviceInformation::FindAllAsync(DeviceClass::VideoCapture))
.then([camera](DeviceInformationCollection^ devices)->DeviceInformation^
{
DeviceInformation^ device = nullptr;
for (unsigned int i = 0; i < devices->Size; i++)
{
device = devices->GetAt(i);
if