自己编写一些代码,因此这项任务并不难。
我已经回答了一个类似的问题,您可以使用答案:
Windows (Phone) 8.1 Camera Use
我在那里重写了我的答案,它包含在设备上查找网络摄像头、初始化您选择的网络摄像头、从中拍照并将其保存在您想要的位置的代码。
该代码适用于 Windows 手机、桌面或平板电脑应用程序,我唯一要更改的是网络摄像头选择,因为用户可能使用外部网络摄像头,也许电脑没有内置网络摄像头。
代码如下:
首先是初始化部分
// First need to find all webcams
DeviceInformationCollection webcamList = await DeviceInformation.FindAllAsync(DeviceClass.All)
(在以下几行中,我得到了前后网络摄像头,但对于非手机应用程序
例如,您最好选择网络摄像头列表的索引 0)
// Then I do a query to find the front webcam
DeviceInformation frontWebcam = (from webcam in webcamList
where webcam.EnclosureLocation != null
&& webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front
select webcam).FirstOrDefault();
// Same for the back webcam
DeviceInformation backWebcam = (from webcam in webcamList
where webcam.EnclosureLocation != null
&& webcam.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back
select webcam).FirstOrDefault();
// Then you need to initialize your MediaCapture
newCapture = new MediaCapture();
await newCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
// Choose the webcam you want
VideoDeviceId = backWebcam.Id,
AudioDeviceId = "",
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview
});
// Set the source of the CaptureElement to your MediaCapture
// (In my XAML I called the CaptureElement *Capture*)
Capture.Source = newCapture;
// Start the preview
await newCapture.StartPreviewAsync();
第二张照片
//Set the path of the picture you are going to take
StorageFolder folder = ApplicationData.Current.LocalFolder;
var picPath = "\\Pictures\\newPic.jpg";
StorageFile captureFile = await folder.CreateFileAsync(picPath, CreationCollisionOption.GenerateUniqueName);
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
//Capture your picture into the given storage file
await newCapture.CapturePhotoToStorageFileAsync(imageProperties, captureFile);
完成!图片保存在您的应用程序存储文件夹中的给定路径。