在Windows 8桌面应用程序中,我需要使用C#4.5中的相机拍摄照片.
我曾尝试使用CameraCaptureUI类,但它不适用于桌面应用程序.
所以我尝试使用MediaCapture类,它可用于Metro应用程序或桌面应用程序.它的工作原理非常好,基于此处的示例:http://code.msdn.microsoft.com/windowsapps/media-capture-sample-adf87622/
var capture = new MediaCapture();
// Find the camera device id to use
string deviceId = "";
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
for (var i = 0; i < devices.Count; i++) {
Console.WriteLine(devices[i]);
deviceId = devices[i].Id;
}
// init the settings of the capture
var settings = new MediaCaptureInitializationSettings();
settings.AudioDeviceId = "";
settings.VideoDeviceId = deviceId;
settings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.Photo;
settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
await capture.InitializeAsync(settings);
// Find the highest resolution available
VideoEncodingProperties resolutionMax = null; …Run Code Online (Sandbox Code Playgroud)