每当我想将我转换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 ");
}
}
Run Code Online (Sandbox Code Playgroud)
这条线
frameBitmap.CopyToBuffer(bitmap.PixelBuffer); …Run Code Online (Sandbox Code Playgroud) 我想检查当前应用程序是否在前台/焦点.该应用程序是一个Windows-10 UWP应用程序.
我已经得到的是,检查当前的应用程序是否最小化.为此,我使用的 VisibilityChanged事件 Window.Current.
但我找不到解决方案,以检测应用程序是否在前台.