每次我想把我的
以下是我转换的代码片段:
SoftwareBitmap
转换成 WriteableBitmap
时,都会出现以下异常:System.Runtime.InteropServices.COMException
。以下是我转换的代码片段:
private async void Start(object sender, RoutedEventArgs e)
{
_MediaCapture = new MediaCapture();
await _MediaCapture.InitializeAsync();
mediaElement.Source = _MediaCapture;
await _MediaCapture.StartPreviewAsync();
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick += HandleTimerTick;
timer.Start();
}
private async void HandleTimerTick(object Sender, object E)
{
var frame = await _MediaCapture.GetPreviewFrameAsync();
SoftwareBitmap frameBitmap = frame.SoftwareBitmap;
WriteableBitmap bitmap = new WriteableBitmap(frameBitmap.PixelWidth, frameBitmap.PixelHeight);
try
{
frameBitmap.CopyToBuffer(bitmap.PixelBuffer);
}
catch (Exception)
{
Debug.WriteLine("Exception ");
}
}
这行
frameBitmap.CopyToBuffer(bitmap.PixelBuffer);
抛出异常。
我正在一个x64远程设备上进行调试。
catch (Exception) { Debug.WriteLine("Exception "); }
是一种非常糟糕的做法。 - Dmitry Bychenko