小编Ray*_*y20的帖子

在Windows 8桌面应用上使用MediaCapture

在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)

c# webcam windows-8 winrt-xaml windows-store-apps

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

webcam ×1

windows-8 ×1

windows-store-apps ×1

winrt-xaml ×1