unosquare / ffmediaelement

FFME: The Advanced WPF MediaElement (based on FFmpeg)
https://unosquare.github.io/ffmediaelement/
Other
1.17k stars 238 forks source link

System.Runtime.InteropServices.ExternalException #574

Closed swimfish09 closed 2 years ago

swimfish09 commented 2 years ago

System.Runtime.InteropServices.ExternalException

Please enter a general description for the issue. Delete sections that are not relevant and provide additional sections if necessary.

Version Information

4.4.350

Steps to Reproduce

capture a image

Sample Code

XAML

<MainWindow>
<Image 
                x:Name="duplicated" 
                Margin="0"/>
</MainWindow>

C

private WriteableBitmap Wb;
        [DllImport("kernel32.dll", EntryPoint = nameof(CopyMemory), SetLastError = false)]
        private static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);

        private void Media_RenderingVideo(object sender, RenderingVideoEventArgs e)
        {
            if (Wb == null || Wb.BackBufferStride != e.Bitmap.Stride || Wb.PixelHeight != e.Bitmap.PixelHeight)
            {
                Wb = new WriteableBitmap(e.Bitmap.PixelWidth, e.Bitmap.PixelHeight, e.Bitmap.DpiX, e.Bitmap.DpiY, PixelFormats.Bgr32, null);
                VideoPlayerZoomAndPanControl.duplicated.Source = Wb;
            }
            Wb.Lock();
            CopyMemory(Wb.BackBuffer, e.Bitmap.Scan0, (uint)(e.Bitmap.Stride * e.Bitmap.PixelHeight));
            Wb.AddDirtyRect(e.Bitmap.UpdateRect);
            Wb.Unlock();
        }

 if (!IsPlaying || !Media.IsPlaying)
                return;
 var image = await Media.CaptureBitmapAsync();
 var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ImageDefaultSavePath);
 if (!Directory.Exists(path))
         Directory.CreateDirectory(path);
var file = Path.Combine(path, $"{(Info.Parent == null ? "" : Info.Parent.Label + "_")}{Info.Label}_{System.DateTime.Now:yyyy_MM_dd_HH_mm_ss}.png");
image?.Save(file, ImageFormat.Png);
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.