【问题标题】:How can I improve WPF drawing application?如何改进 WPF 绘图应用程序?
【发布时间】:2011-07-07 04:06:04
【问题描述】:

以下是我将图像绘制为边框对象背景的代码。

   void DrawImage()
   {     
        MemoryStream ms = new MemoryStream();
        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
        System.Windows.Media.Imaging.BitmapImage chartBitmapImage = new System.Windows.Media.Imaging.BitmapImage();
        chartBitmapImage.BeginInit();
        chartBitmapImage.StreamSource = new MemoryStream(ms.ToArray());
        chartBitmapImage.EndInit();
        imageBrush.ImageSource = chartBitmapImage;            
        aBorder.Background = imageBrush;
        ...
   }

上面的 DrawImage() 方法每秒钟调用一次。 所有操作都运行良好,但速度太慢。

我想提高性能。 有什么改进的地方吗? 也许,我想任何 bmp 图像处理方法都比我使用的更好。 帮帮我...

【问题讨论】:

  • 您的图像是否在每次绘制时都会发生变化 - 如果没有,为什么不保存并重复使用它(或仅在它发生变化时更新它)?
  • 我的图片每秒都在变化。
  • 它是否会在一个周期内发生变化(因此您获得的不同图像数量有限),还是每个图像都不同?

标签: wpf performance image bmp


【解决方案1】:
  1. 分析代码以找到最慢的代码行。
  2. 让该部分运行得更快。
  3. 重复直到性能可以接受。

【讨论】:

    猜你喜欢
    • 2012-05-09
    • 2012-10-28
    • 2010-12-07
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多