【发布时间】:2011-03-03 15:15:16
【问题描述】:
我正在 WPF 应用程序中编写一个模拟生活游戏的程序。 如何执行类似 GDI+ 的图形操作以创建包含单元格网格的图像?
(通常,在 WinForms 中,我会知道如何执行此操作)。
编辑: 我使用了这段代码:
WriteableBitmap wb = new WriteableBitmap(width * 5, height * 5, 100, 100, new PixelFormat(), new BitmapPalette(new List<Color> { Color.FromArgb(255, 255, 0, 0) }));
wb.WritePixels(new Int32Rect(0, 0, 5, 5), new IntPtr(), 3, 3);
Background.Source = wb;
背景是System.Windows.Controls.Image 控件
【问题讨论】:
-
您是否想过使用 WPF
Grid和Rectangles?您甚至可以获得更好的性能,因为一切都是基于矢量的