本文整理汇总了C#中Windows.Media.Capture.MediaCapture类的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture类的具体用法?C# MediaCapture怎么用?C# MediaCapture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MediaCapture类属于Windows.Media.Capture命名空间,在下文中一共展示了MediaCapture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCapturePreview
private async Task GetCapturePreview()
{
_capture = new MediaCapture();
var Videodevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
//var rearCamera = Videodevices.FirstOrDefault(item => item.EnclosureLocation != null && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
var frontCamera = Videodevices.FirstOrDefault(item => item.EnclosureLocation != null && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);
//TODO: カメラを切り替えられるようにする。
try
{
await _capture.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoDeviceId = frontCamera.Id
});
}
catch (Exception ex)
{
var message = new MessageDialog(ex.Message, "おや?なにかがおかしいようです。");
await message.ShowAsync();
}
capturePreview.Source = _capture;
await _capture.StartPreviewAsync();
}
示例2: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
Status.Text = "Status: " + "App started";
//compass
var compass = Windows.Devices.Sensors.Compass.GetDefault();
compass.ReportInterval = 10;
//compass.ReadingChanged += compass_ReadingChanged;
Status.Text = "Status: " + "Compass started";
//geo
var gloc = new Geolocator();
gloc.GetGeopositionAsync();
gloc.ReportInterval = 60000;
gloc.PositionChanged += gloc_PositionChanged;
Status.Text = "Status: " + "Geo started";
//Accelerometer
var aclom = Accelerometer.GetDefault();
aclom.ReportInterval = 1;
aclom.ReadingChanged += aclom_ReadingChanged;
//foursquare
await GetEstablishmentsfromWed();
//camera
var mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
CaptureElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
Status.Text = "Status: " + "Camera feed running";
}
示例3: 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);
}
示例4: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
if (_mediaCapture == null)
{
// Attempt to get te back camera if one is available, but use any camera device if not
var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
DeviceInformation desiredDevice = allVideoDevices.FirstOrDefault(
x => x.EnclosureLocation != null & x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
var cameraDevice = desiredDevice ?? allVideoDevices.FirstOrDefault();
if (cameraDevice == null)
{
// TODO: Implement an error experience for camera-less devices
Debug.Write("No camera device found.");
return;
}
// Create MediaCapture and its setings
_mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
// TODO: Implement an error experience for non-authorized case
await _mediaCapture.InitializeAsync(settings);
// Startin the preview
PreviewControl.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();
}
}
示例5: ViewfinderPage
public ViewfinderPage()
{
InitializeComponent();
_navigationHelper = new NavigationHelper(this);
_photoCaptureManager = new MediaCapture();
_dataContext = FilterEffects.DataContext.Instance;
}
示例6: Start_Capture_Preview_Click
async private void Start_Capture_Preview_Click(object sender, RoutedEventArgs e)
{
captureManager = new MediaCapture(); //Define MediaCapture object
await captureManager.InitializeAsync(); //Initialize MediaCapture and
capturePreview.Source = captureManager; //Start preiving on CaptureElement
await captureManager.StartPreviewAsync(); //Start camera capturing
}
示例7: Grid_Loaded
private async void Grid_Loaded(object sender, RoutedEventArgs e)
{
var camera = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)).FirstOrDefault();
if (camera != null)
{
mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings() { VideoDeviceId = camera.Id };
await mediaCapture.InitializeAsync(settings);
displayRequest.RequestActive();
VideoPreview.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
memStream = new InMemoryRandomAccessStream();
MediaEncodingProfile mediaEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
await mediaCapture.StartRecordToStreamAsync(mediaEncodingProfile, memStream);
}
//video = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Video);
//if (video!=null)
//{
// MediaClip mediaClip = await MediaClip.CreateFromFileAsync(video);
// mediaComposition.Clips.Add(mediaClip);
// mediaStreamSource = mediaComposition.GeneratePreviewMediaStreamSource(600, 600);
// VideoPreview.SetMediaStreamSource(mediaStreamSource);
//}
//FFMPEGHelper.RTMPEncoder encoder = new FFMPEGHelper.RTMPEncoder();
//encoder.Initialize("rtmp://youtube.co");
}
示例8: Reader
/// <summary>
/// Initializes a new instance of the <see cref="Reader" /> class.
/// </summary>
/// <param name="capture">MediaCapture instance.</param>
/// <param name="width">Capture frame width.</param>
/// <param name="height">Capture frame height.</param>
public Reader(MediaCapture capture, uint width, uint height)
{
this.capture = capture;
this.encodingProps = new ImageEncodingProperties { Subtype = "BMP", Width = width, Height = height};
this.barcodeFound = false;
this.cancelSearch = new CancellationTokenSource();
}
示例9: InitCamera_Click
private async void InitCamera_Click(object sender, RoutedEventArgs e)
{
captureManager = new MediaCapture();
await captureManager.InitializeAsync();
// Can only read capabilities after capture device initialized.
VideoDeviceController videoDeviceController = captureManager.VideoDeviceController;
SceneModeControl sceneModeControl = _scene = videoDeviceController.SceneModeControl;
RegionsOfInterestControl regionsOfInterestControl = _regions = videoDeviceController.RegionsOfInterestControl;
bool isFocusSupported = _focus = videoDeviceController.FocusControl.Supported;
bool isIsoSpeedSupported = _iso = videoDeviceController.IsoSpeedControl.Supported;
bool isTorchControlSupported = _torch = videoDeviceController.TorchControl.Supported;
bool isFlashControlSupported = _flash = videoDeviceController.FlashControl.Supported;
if (_scene != null)
{
foreach (CaptureSceneMode mode in _scene.SupportedModes)
{
string t = mode.ToString();
}
}
if (_regions != null)
{
bool autoExposureSupported = _regions.AutoExposureSupported;
bool autoFocusSupported = _regions.AutoFocusSupported;
bool autoWhiteBalanceSupported = _regions.AutoWhiteBalanceSupported;
uint maxRegions = _regions.MaxRegions;
}
}
示例10: Loaded
private async void Loaded(object sender, RoutedEventArgs e)
{
MediaCapture capMana = new MediaCapture();
await capMana.InitializeAsync();
Webcam_Logitech.Source = capMana;
await capMana.StartPreviewAsync();
}
示例11: InitializeCameraAsync
private async Task InitializeCameraAsync()
{
if (mediaCapture == null)
{
// get camera device (back camera preferred)
var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Back);
if (cameraDevice == null)
{
Debug.WriteLine("no camera device found");
return;
}
// Create MediaCapture and its settings
mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
// Initialize MediaCapture
try
{
await mediaCapture.InitializeAsync(settings);
isInitialized = true;
}
catch (UnauthorizedAccessException)
{
Debug.WriteLine("access to the camera denied");
}
}
}
示例12: OnNavigatedTo
protected override void OnNavigatedTo(NavigationEventArgs e)
{
captureManager = new MediaCapture();
reader = new BarcodeReader();
PreviewCameraFeed();
}
示例13: Start
public async void Start(int camIndex)
{
// devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (devices.Count > 0)
{
// Using Windows.Media.Capture.MediaCapture APIs to stream from webcam
mediaCaptureMgr = new MediaCapture();
///////////////////////////////////
var captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Video;
captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview;
captureInitSettings.VideoDeviceId = devices[camIndex].Id;
///////////////////////////////////
await mediaCaptureMgr.InitializeAsync(captureInitSettings);
SetResolution();
camCaptureElement.Source = mediaCaptureMgr;
await mediaCaptureMgr.StartPreviewAsync();
}
}
示例14: ReadAsync
/// <summary>
/// Continuously look for a QR code
/// NOTE: this method won't work if recording is enabled ('hey Cortana, start recording' thing).
/// </summary>
public static async Task<string> ReadAsync(CancellationToken token = default(CancellationToken))
{
var mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
await mediaCapture.AddVideoEffectAsync(new MrcVideoEffectDefinition(), MediaStreamType.Photo);
var reader = new BarcodeReader();
reader.Options.TryHarder = false;
while (!token.IsCancellationRequested)
{
var imgFormat = ImageEncodingProperties.CreateJpeg();
using (var ras = new InMemoryRandomAccessStream())
{
await mediaCapture.CapturePhotoToStreamAsync(imgFormat, ras);
var decoder = await BitmapDecoder.CreateAsync(ras);
using (var bmp = await decoder.GetSoftwareBitmapAsync())
{
Result result = await Task.Run(() =>
{
var source = new SoftwareBitmapLuminanceSource(bmp);
return reader.Decode(source);
});
if (!string.IsNullOrEmpty(result?.Text))
return result.Text;
}
}
await Task.Delay(DelayBetweenScans);
}
return null;
}
示例15: cameraCapture_Failed
private async void cameraCapture_Failed(MediaCapture sender, MediaCaptureFailedEventArgs errorEventArgs)
{
// It's safest to return this back onto the UI thread to show the message dialog.
MessageDialog dialog = new MessageDialog(errorEventArgs.Message);
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
async () => { await dialog.ShowAsync(); });
}