Ogni volta che voglio convertire il mio SoftwareBitmap
in un WriteableBitmap
ottengo la seguente eccezione: System.Runtime.InteropServices.COMException
.Converti SoftwareBitmap in WriteableBitmap
Ecco il mio frammento di codice per questo:
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 ");
}
}
La linea
frameBitmap.CopyToBuffer(bitmap.PixelBuffer);
sta gettando l'eccezione.
Sto eseguendo il debug su un dispositivo remoto x64.
Qual è l'eccezione generata? –
@Dmitry Bychenko Guarda sopra: System.Runtime.InteropServices.COMException – TheTanic
Nota a margine: * deglutizione * eccezioni come 'catch (Exception) {Debug.WriteLine (" Exception "); } 'è una * pessima pratica *. –