本文整理汇总了C#中Windows.Media.Capture.MediaCapture.CapturePhotoToStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture.CapturePhotoToStreamAsync方法的具体用法?C# MediaCapture.CapturePhotoToStreamAsync怎么用?C# MediaCapture.CapturePhotoToStreamAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Media.Capture.MediaCapture
的用法示例。
在下文中一共展示了MediaCapture.CapturePhotoToStreamAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: Run
private async void Run()
{
await _HubConnection.Start();
var cam = new MediaCapture();
await cam.InitializeAsync(new MediaCaptureInitializationSettings()
{
MediaCategory = MediaCategory.Media,
StreamingCaptureMode = StreamingCaptureMode.Video
});
_Sensor.MotionDetected += async (int pinNum) =>
{
var stream = new InMemoryRandomAccessStream();
Stream imageStream = null;
try
{
await Task.Factory.StartNew(async () =>
{
_Sensor.IsActive = false;
await cam.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
stream.Seek(0);
imageStream = stream.AsStream();
imageStream.Seek(0, SeekOrigin.Begin);
string imageUrl = await NotificationHelper.UploadImageAsync(imageStream);
switch (await OxfordHelper.IdentifyAsync(imageUrl))
{
case AuthenticationResult.IsOwner:
// open the door
MotorController.PWM(26);
break;
case AuthenticationResult.Unkown:
// send notification to the owner
NotificationHelper.NotifyOwnerAsync(imageUrl);
break;
case AuthenticationResult.None:
default:
break;
}
_Sensor.IsActive = true;
});
}
finally
{
if (stream != null)
stream.Dispose();
if (imageStream != null)
imageStream.Dispose();
}
};
}
示例3: ScanButton
//.........这里部分代码省略.........
tcs.TrySetResult(null);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
};
bw.RunWorkerAsync();
#else
var cameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (cameras.Count < 1)
{
return;
}
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameras.Last().Id };
var imageSource = new MediaCapture();
await imageSource.InitializeAsync(settings);
CaptureElement previewRect = new CaptureElement() { Width = 640, Height = 360 };
previewRect.Source = imageSource;
sp.Children.Add(previewRect);
await imageSource.StartPreviewAsync();
bool keepGoing = true;
Action a = null;
a = async () =>
{
if (!keepGoing) return;
var stream = new InMemoryRandomAccessStream();
await imageSource.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
stream.Seek(0);
var tmpBmp = new WriteableBitmap(1, 1);
await tmpBmp.SetSourceAsync(stream);
var writeableBmp = new WriteableBitmap(tmpBmp.PixelWidth, tmpBmp.PixelHeight);
stream.Seek(0);
await writeableBmp.SetSourceAsync(stream);
Result _result = null;
var barcodeReader = new BarcodeReader
{
// TryHarder = true,
AutoRotate = true
};
try
{
_result = barcodeReader.Decode(writeableBmp);
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
stream.Dispose();
if (_result != null)
{
result = _result.Text;
Debug.WriteLine(_result.Text);