Tag: bitmapsource

快速将Bitmap转换为BitmapSource wpf

我需要在30Hz处在Image组件上绘制图像。 我用这个代码: public MainWindow() { InitializeComponent(); Messenger.Default.Register(this, (bmp) => { ImageTarget.Dispatcher.BeginInvoke((Action)(() => { var hBitmap = bmp.GetHbitmap(); var drawable = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); DeleteObject(hBitmap); ImageTarget.Source = drawable; })); }); } 问题是,使用此代码,我的CPU使用率约为80%,如果没有转换,则大约为6%。 那么为什么转换位图这么长? 是否有更快的方法(使用不安全的代码)?