小编aus*_*nem的帖子

需要一些东西在WPF中快速绘制许多图像

我正在研究.NET 3.5中的细胞自动机生成器.我决定使用WPF因为我想学习WPF中的新东西.

我像规则30和二维像生命一样绘制一维自动机.

我需要一些东西来快速绘制许多图像.

例如,网格的尺寸是64×64,单元的尺寸是12px.所以我一步画出64*64 = 4096张图像.并且一步之间的间隔约为100毫秒.

我将我的应用程序重写为WinForms,并且一切正常.但在WPF很慢,我不知道为什么.


我在WPF中绘图的例子:

我有一个派生自Image的类.在这个类中我绘制了一个位图,我在Source属性中使用它.

        public void DrawAll()
    {

        DrawingGroup dg = new DrawingGroup();


        for (byte i = 0; i < this.DimensionX; ++i)
        {

            for (byte j = 0; j < this.DimensionY; ++j)
            {

                Piece p = this.Mesh[i][j];

                Rect rect = new Rect(j * this.CellSize + (j + 1), i * this.CellSize + (i + 1),
                    this.CellSize, this.CellSize);

                ImageDrawing id = new ImageDrawing();
                id.Rect = rect;

                if (p == null)
                    id.ImageSource = this._undefinedPiece.Image.Source; …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf

5
推荐指数
1
解决办法
2245
查看次数

标签 统计

.net ×1

c# ×1

wpf ×1