[英]c# UWP Camera preview
我使用以下代碼創建了一個攝像機捕獲:
CameraCaptureUI capture = new CameraCaptureUI();
capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
capture.PhotoSettings.CroppedAspectRatio = new Windows.Foundation.Size(3, 5);
capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable;
storeFile = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (storeFile != null)
{
BitmapImage bimage = new BitmapImage();
stream = await storeFile.OpenAsync(FileAccessMode.Read);
bimage.SetSource(stream);
captureImage.Source = bimage;
}
但是,它將打開新窗口以捕獲照片,並打開另一個窗口以對其進行裁剪。
我想直接訪問我的相機並在xaml窗口中顯示它的預覽。 有什么建議嗎?
我想直接訪問我的相機並在xaml窗口中顯示它的預覽。 有什么建議嗎?
您還可以使用MediaCapture
類進行攝像機捕獲,該類用於捕獲攝像機的音頻,視頻和圖像。 有關如何顯示相機預覽的指導。 請參閱顯示相機預覽 。 要快速開始捕獲照片,音頻或視頻,請參閱使用MediaCapture捕獲基本的照片,視頻和音頻 。
如果要將照片捕獲到文件中,可以使用以下代碼實現。
var myPictures = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures);
StorageFile file = await myPictures.SaveFolder.CreateFileAsync("photo.jpg", CreationCollisionOption.GenerateUniqueName);
using (var captureStream = new InMemoryRandomAccessStream())
{
await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), captureStream);
using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var decoder = await BitmapDecoder.CreateAsync(captureStream);
var encoder = await BitmapEncoder.CreateForTranscodingAsync(fileStream, decoder);
var properties = new BitmapPropertySet {
{ "System.Photo.Orientation", new BitmapTypedValue(PhotoOrientation.Normal, PropertyType.UInt16) }
};
await encoder.BitmapProperties.SetPropertiesAsync(properties);
await encoder.FlushAsync();
}
}
這是相對的代碼示例 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.