本文整理汇总了C#中Windows.Media.Capture.MediaCapture.SetPreviewRotation方法的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture.SetPreviewRotation方法的具体用法?C# MediaCapture.SetPreviewRotation怎么用?C# MediaCapture.SetPreviewRotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Media.Capture.MediaCapture
的用法示例。
在下文中一共展示了MediaCapture.SetPreviewRotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: This_Loaded
private async void This_Loaded( object sender, RoutedEventArgs e )
{
try
{
_camera = new MediaCapture();
await _camera.InitializeAsync( new MediaCaptureInitializationSettings
{
VideoDeviceId = ( await GetBackCameraAsync() ).Id,
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview
} );
_camera.VideoDeviceController.FlashControl.Enabled = false;
_camera.SetPreviewRotation( VideoRotation.Clockwise90Degrees );
_camera.SetRecordRotation( VideoRotation.Clockwise90Degrees );
CameraPreview.Source = _camera;
await _camera.StartPreviewAsync();
StartScanning();
}
catch
{
ErrorMessage.Visibility = Visibility.Visible;
}
}
示例2: StartPreviewAsync
public async Task StartPreviewAsync(VideoRotation videoRotation)
{
try
{
if (mediaCapture == null)
{
var cameraDevice = await FindCameraDeviceByPanelAsync(Panel.Back);
mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
await mediaCapture.InitializeAsync(settings);
captureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
isPreviewing = true;
mediaCapture.SetPreviewRotation(videoRotation);
displayRequest.RequestActive();
}
//DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
}
catch (UnauthorizedAccessException)
{
// This will be thrown if the user denied access to the camera in privacy settings
Debug.WriteLine("The app was denied access to the camera");
}
catch (Exception ex)
{
Debug.WriteLine("MediaCapture initialization failed. {0}", ex.Message);
}
}
示例3: IniciaPreviaCapturaFoto
async private void IniciaPreviaCapturaFoto(object sender, RoutedEventArgs e)
{
GerenteCaptura = new Windows.Media.Capture.MediaCapture();
await GerenteCaptura.InitializeAsync();
GerenteCaptura.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
CapturaPrevia.Source = GerenteCaptura;
await GerenteCaptura.StartPreviewAsync();
}
示例4: initCamera
private async void initCamera()
{
if (camera == null)
{
camera = new MediaCapture();
await camera.InitializeAsync();
camera.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
camera.SetRecordRotation(VideoRotation.Clockwise270Degrees);
}
CameraPreview.Source = camera;
await camera.StartPreviewAsync();
}
示例5: InitializeAsync
public async Task InitializeAsync()
{
// Discover all the cameras
await EnumerateCamerasAsync();
// Create a camera preview image source (from Imaging SDK)
captureManager = new MediaCapture();
MediaCaptureInitializationSettings captureSettings = new MediaCaptureInitializationSettings();
captureSettings.VideoDeviceId = backCamera.Id;
await captureManager.InitializeAsync(captureSettings);
CameraPreview.Source = captureManager;
captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
await captureManager.StartPreviewAsync();
}
示例6: IniciaPreviaCapturaFoto
async private void IniciaPreviaCapturaFoto(object sender, RoutedEventArgs e)
{
GerenteCaptura = new Windows.Media.Capture.MediaCapture();
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Front);
await GerenteCaptura.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.Photo,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id,
});
GerenteCaptura.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
CapturaPrevia.Source = GerenteCaptura;
await GerenteCaptura.StartPreviewAsync();
}
示例7: Initialize
public async Task<MediaCapture> Initialize(CaptureUse primaryUse = CaptureUse.Photo)
{
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
mediaCapture = new MediaCapture();
if (devices.Count() > 0)
{
await this.mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = devices.ElementAt(1).Id, PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview });
}
mediaCapture.VideoDeviceController.PrimaryUse = primaryUse;
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
imgEncodingProperties = ImageEncodingProperties.CreateJpeg();
imgEncodingProperties.Width = 640;
imgEncodingProperties.Height = 480;
videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
return mediaCapture;
}
示例8: OnNavigatedTo
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
// Create MediaCapture and init
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
// Assign to Xaml CaptureElement.Source and start preview
capturePreview.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
}
示例9: InitCamera
//private void orientView()
//{
// var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
// grid.Height = bounds.Height;
// grid.Width = bounds.Width;
// var displayInfo = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
// switch (displayInfo.CurrentOrientation)
// {
// case Windows.Graphics.Display.DisplayOrientations.Landscape:
// mediaCapture.SetPreviewRotation(VideoRotation.None);
// break;
// case Windows.Graphics.Display.DisplayOrientations.LandscapeFlipped:
// mediaCapture.SetPreviewRotation(VideoRotation.Clockwise180Degrees);
// break;
// case Windows.Graphics.Display.DisplayOrientations.Portrait:
// mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
// break;
// case Windows.Graphics.Display.DisplayOrientations.PortraitFlipped:
// mediaCapture.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
// break;
// }
//}
async private void InitCamera()
{
if (App.APP_SETTINGS.Cameras.Count > 0)
{
try
{
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { VideoDeviceId = App.APP_SETTINGS.Cameras[App.APP_SETTINGS.SelectedCamera].ID, PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview, StreamingCaptureMode = StreamingCaptureMode.Video });
SetResolution();
capturePreview.Source = mediaCapture;
//orientView();
if(App.IsMobile)
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
await mediaCapture.StartPreviewAsync();
if (mediaCapture.VideoDeviceController.FocusControl.Supported)
{
await mediaCapture.VideoDeviceController.FocusControl.SetPresetAsync(Windows.Media.Devices.FocusPreset.AutoNormal);
}
else
{
FocusText.Visibility = Visibility.Collapsed;
}
if(!mediaCapture.VideoDeviceController.TorchControl.Supported)
{
btnTorch.Visibility = Visibility.Collapsed;
}
beginCapture();
}
catch (Exception ex)
{
}
}
else
{
NoCamera.Visibility = Visibility.Visible;
}
}
示例10: InitializePreview
public async Task InitializePreview(CaptureElement captureElement)
{
captureManager = new MediaCapture();
var cameraID = await GetCameraID(Panel.Back);
if (cameraID == null)
{
return;
}
await captureManager.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.Photo,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
await
captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo,
maxResolution());
captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
StartPreview(captureElement);
}
示例11: InitialAsync
public async Task InitialAsync(CaptureElement captureElement, MediaEncodingProfile profile = null, bool BackCamera = false)
{
if (initialized)
Dispose(true);
initialized = true;
this.captureElement = captureElement;
this.activeProfile = profile;
if (CameraDeviceList == null)
await EnumerateCameras();
mediaCapture = null;
mediaCapture = new MediaCapture();
IsBackCamera = BackCamera;
captureInitSettings = InitCaptureSettings(IsBackCamera);
await mediaCapture.InitializeAsync(captureInitSettings);
mediaCapture.VideoDeviceController.DesiredOptimization = MediaCaptureOptimization.LatencyThenQuality;
mediaCapture.CameraStreamStateChanged += MediaCapture_CameraStreamStateChanged;
mediaCapture.Failed += MediaCapture_Failed;
mediaCapture.FocusChanged += MediaCapture_FocusChanged;
mediaCapture.PhotoConfirmationCaptured += MediaCapture_PhotoConfirmationCaptured;
mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded;
mediaCapture.ThermalStatusChanged += MediaCapture_ThermalStatusChanged;
await SetResolutionAsync();
if (Manager.DeviceService.CurrentDevice() == DeviceTypes.Mobile)
{
if (IsBackCamera)
{
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
}
else
{
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
}
}
activeProfile = CreateProfile();
mediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Video;
captureElement.Source = mediaCapture;
}
示例12: InitiateCameraCaptureObject
private async Task InitiateCameraCaptureObject(Panel deviceLocation)
{
try
{
if (_bInitializingCamera || _cameraCapture != null) return;
_bInitializingCamera = true;
await InitCaptureSettings(deviceLocation);
_cameraCapture = new MediaCapture();
await _cameraCapture.InitializeAsync(_captureInitSettings);
//Enable QR Detector
if (_qrDetectionModeEnabled)
{
var formats = _cameraCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
var format = (VideoEncodingProperties)formats.OrderBy((item) =>
{
var props = (VideoEncodingProperties)item;
return Math.Abs(props.Height - ActualWidth) + Math.Abs(props.Width - ActualHeight);
}).First();
await _cameraCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, format);
var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, format.Width >= format.Height ? format.Width : format.Height, AnalyzeImage);
await _cameraCapture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties);
_barcodeReader = _barcodeReader ?? new BarcodeReader
{
Options = new DecodingOptions
{
PossibleFormats = new[] { BarcodeFormat.QR_CODE, BarcodeFormat.CODE_128 },
TryHarder = true
}
};
}
PhotoPreview.Source = _cameraCapture;
await _cameraCapture.StartPreviewAsync();
_cameraCapture.Failed += CameraCaptureOnFailed;
_scannerAutoFocus = await ScannerAutoFocus.StartAsync(_cameraCapture.VideoDeviceController.FocusControl);
_cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
}
catch (Exception ex)
{
WindowsPhoneUtils.Log(ex.Message);
}
_bInitializingCamera = false;
}
示例13: CaptureImage
private async Task CaptureImage()
{
cameraCapture = new MediaCapture();
cameraCapture.Failed += cameraCapture_Failed;
await cameraCapture.InitializeAsync();
#if WINDOWS_PHONE_APP
cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
cameraCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
#endif
captureGrid.Visibility = Windows.UI.Xaml.Visibility.Visible;
previewElement.Visibility = Windows.UI.Xaml.Visibility.Visible;
previewElement.Source = cameraCapture;
await cameraCapture.StartPreviewAsync();
}
示例14: Start_Capture_Preview_Click
async private void Start_Capture_Preview_Click()
{
//var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Front);
var Videodevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var cameraDevice = Videodevices.FirstOrDefault(item => item.EnclosureLocation != null && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
if (cameraDevice == null)
{
Debug.WriteLine("No camera device found!");
return;
}
// Create MediaCapture and its settings
captureManager = new MediaCapture();
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
// Initialize MediaCapture
try
{
await captureManager.InitializeAsync(settings);
// just after initialization
var maxResolution = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate(
(i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);
captureManager.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
_isInitialized = true;
}
catch (UnauthorizedAccessException)
{
Debug.WriteLine("The app was denied access to the camera");
}
catch (Exception ex)
{
Debug.WriteLine("Exception when initializing MediaCapture with {0}: {1}", cameraDevice.Id, ex.ToString());
}
capturePreview.Source = captureManager; //Start preiving on CaptureElement
await captureManager.StartPreviewAsync(); //Start camera capturing
}
示例15: StartCamera
async void StartCamera()
{
var cameraID = await GetCameraID(Windows.Devices.Enumeration.Panel.Back);
mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video,
PhotoCaptureSource = PhotoCaptureSource.VideoPreview,
AudioDeviceId = string.Empty,
VideoDeviceId = cameraID.Id
});
//var maxResolution = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate((i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
//await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);
var maxResolution = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).Aggregate(
(i1, i2) => (i1 as VideoEncodingProperties).Width > (i2 as VideoEncodingProperties).Width ? i1 : i2);
await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, maxResolution);
mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
//mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
CameraPreview.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
}