我有从网络摄像头获取照片的代码。我需要编写一个机制来完成这个过程。我该怎么做呢?我有以下代码:
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
var memStream3 = new Windows.Storage.Streams.InMemoryRandomAccessStream();
var mediaCaptureMgr1 = new MediaCapture();
await mediaCaptureMgr1.InitializeAsync();
mediaCaptureMgr1.SetPreviewMirroring(true);
await mediaCaptureMgr1.CapturePhotoToStreamAsync(imageProperties, memStream3);
await memStream3.FlushAsync();
memStream3.Seek(0);
WriteableBitmap wb1 = new WriteableBitmap(320, 240);
wb1.SetSource(memStream3);
//1
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(0.1));
//if CapturePhotoToStreamAsync finished? OR memStream3 not null?
//break;
}
//2
如果我在 //1 开始对 wb1 进行任何操作,我将无法工作,因为 wb1 = null。如果我在 //2 开始做 wb1! = null 因为我等到所有异步功能都完成了。