我需要以Image30Hz的频率在组件上绘制图像。我使用此代码:
public MainWindow()
{
InitializeComponent();
Messenger.Default.Register<Bitmap>(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%。
那为什么转换位图这么长呢?
是否有更快的方法(使用不安全的代码)?
蛊毒传说
呼啦一阵风
相关分类