WPF render performance with BitmapSource

后端 未结 2 675
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-03 14:12

I\'ve created a WPF control (inheriting from FrameworkElement) that displays a tiled graphic that can be panned. Each tile is 256x256 pixels at 24bpp. I\'ve overridden OnRender.

2条回答
  •  孤街浪徒
    2021-02-03 14:37

    Also try these;

    /* ivis is declared in XAML  */
    
    iVis.Stretch = Stretch.None;
    RenderOptions.SetBitmapScalingMode(iVis, BitmapScalingMode.NearestNeighbor);
    RenderOptions.SetEdgeMode(iVis, EdgeMode.Aliased);
    VisualBitmapScalingMode = BitmapScalingMode.NearestNeighbor;
    iVis.Source = **** your bitmap source ****
    

    I was having some trouble with performance when using a huge amount of "A" channel color's, waiting until after the image had rendered to scale it worked much better for me.

    Also, as you said your using a tiled graphic?

    You would usually use a TileBrush to simply set as the Brush on your FrameworkElement. If you are animating them or adding new ones dynamically, you could generate your brushes then apply them to your object as you go manually too, be sure to Freeze them if you can. Also, VisualBitmapScalingMode is a property of any Visual.

提交回复
热议问题