Nas*_*aer 5 .net wpf performance image image-processing
我在.Net 4.0中的WPF工作.我有一些相机1392x1040像素的巨大图像.每个帧都会出现,System.Drawing.Bitmap并将通过使用转换为BitmapImage
Public Function BitmapToWpfBitmapSource(ByVal bmSrc As System.Drawing.Bitmap) As BitmapSource
If bmSrc Is Nothing Then Return Nothing
Dim res As BitmapSource
Dim Ptr As IntPtr
Ptr = bmSrc.GetHbitmap(System.Drawing.Color.Black) 'Create GDI bitmap object
res = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Ptr, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bmSrc.Width, bmSrc.Height))
Dim ret As Integer = DeleteObject(Ptr) 'Delete GDI bitmap object
GC.Collect() 'Because the code is not managed, we need to call the collector manually to avoid memory spikes
Return res
End Function
Run Code Online (Sandbox Code Playgroud)
如果我在GUI中更新图像,我可以获得大约7帧/秒.
通过降低质量可以提高速度:
RenderOptions.SetBitmapScalingMode(Me.ucWindow1.VideoPresenter1.img1, BitmapScalingMode.NearestNeighbor)
使用线程更新每一帧
Dim dl As New SetImageDelegate(AddressOf UpdateImageInGuiGuiThread)Me.Dispatcher.Invoke(dl,imgSrc)
使用32位和24位图像进行测试 - 比较Imageformat
使用性能分析套件进行帧率计数
但CPU仍然是大约10%而不是100%,帧率大约是12FPS而不是39(Winforms).
如何提高相机的帧率?