数据绑定性能问题 [英] Data binding performance issues

查看:152
本文介绍了数据绑定性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个可以显示几何尺寸的地图控件。为了更好的表现,我使用 DrawingVisual s绘制所有的几何图形,然后我写入一个 RenderTargetBitmap ,如代码所示以下:

  public class Map {
public ImageSource MapDrawingImage {get; set;}

private void RenderMap(){
MapDrawingImage = new RenderTargetBitmap(w,h,96,96,PixelFormats.Pbgra32);
foreach(map.Layers中的图层){
System.Windows.Media.DrawingVisual layerDrawing = Render(layer,map);
MapDrawingImage.Render(layerDrawing);
}
}
}

为了显示地图,主窗口有一个 Image 控件,其中 Source 设置为 Map.MapDrawingImage 图像源。要自动更新图像,我使用以下数据绑定:

  RenderOptions.SetBitmapScalingMode(mapImage,BitmapScalingMode.LowQuality); 
//映射图像绑定
绑定mapBinding = new Binding();
mapBinding.Source = map;
mapBinding.Path = new PropertyPath(MapDrawingImage);
mapImage.SetBinding(System.Windows.Controls.Image.SourceProperty,mapBinding);

当地图是静态的时,这个效果非常好。然而,在以每秒5到10次的速率更新地图的动态模式中,数据绑定似乎落后并且应用程序变慢。我搜索了很长时间,我发现:


  1. RenderTargetBitmap 不使用硬件加速,从而在渲染地图时造成一些延迟。

  2. 数据绑定也可能会导致一些延迟刷新地图图像

有没有更好的方法来改善地图表现( RenderTargetBitmap 替换,数据绑定改进)?



提前感谢

解决方案

数据绑定在单独的线程中更新。所以这永远是一个拖延。也可以使用队列,所以当数据绑定不能跟上队列会越来越大。解决方案是,您使用静态图像并更改图像本身,而不是用另一个图像替换图像。


I am writing a map control that can display a bench of geometries. For better performance, I draw all my geometries using DrawingVisuals which I then write into a RenderTargetBitmap as shown in the code below:

public class Map{
   public ImageSource MapDrawingImage{get;set;}

   private void RenderMap(){
    MapDrawingImage= new RenderTargetBitmap(w, h, 96, 96, PixelFormats.Pbgra32);
    foreach (Layer layer in map.Layers) {
        System.Windows.Media.DrawingVisual layerDrawing = Render(layer, map);
        MapDrawingImage.Render(layerDrawing);
    }
   }
}

In order to display the map, the main window has an Image control which Source is set to Map.MapDrawingImage image source. To automatically update the image, I use the following data binding:

    RenderOptions.SetBitmapScalingMode(mapImage, BitmapScalingMode.LowQuality);
    // Map image binding
    Binding mapBinding = new Binding();
    mapBinding.Source = map;
    mapBinding.Path = new PropertyPath("MapDrawingImage");
    mapImage.SetBinding(System.Windows.Controls.Image.SourceProperty, mapBinding); 

This works very well when the map is static. However, in a dynamic mode where the map is updated at a rate of 5 to 10 times a second, the data binding seems to fall a bit short behind and the application slows down. I have searched for long days and I found out that:

  1. RenderTargetBitmap does not use hardware acceleration thus causing some delays when rendering the map.
  2. Data binding might also cause some delays refreshing the map image

Is there any better way to improve the map performance (RenderTargetBitmap replacement, data binding improvement) ?

Thanks in advance,

解决方案

Databinding is updated in a seperate thread. So this will always be with a delay. Also it works with a queue, so when the databinding can't keep up the queue will grow bigger and bigger. The solution would be that you use an image which is static and change the image itself instead of replacing it with another image.

这篇关于数据绑定性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆