【发布时间】:2015-10-28 08:32:17
【问题描述】:
每当我想将我的 SoftwareBitmap 转换为 WriteableBitmap 时,我都会收到以下异常:
System.Runtime.InteropServices.COMException.
这是我的代码 sn-p:
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 RemoteDevice 上调试它。
【问题讨论】:
-
抛出了什么异常?
-
@Dmitry Bychenko 看上面:System.Runtime.InteropServices.COMException
-
旁注:吞下像
catch (Exception) { Debug.WriteLine("Exception "); }这样的例外是一种非常糟糕的做法。 -
我知道。只是为了澄清存在问题。但是谢谢你的笔记
-
为了将来参考,SDK 示例在这里:github.com/Microsoft/Windows-universal-samples/tree/master/…