问题描述
如何昂贵是它创建GDI刷子和笔吗?我应该在一个需要添加基础创建它们,然后将它们包装一个使用,使他们迅速布置,或者我应该创建一个静态类类似System.Drawing.Brushes类?
How expensive is it to create gdi brushes and pens? Should I create them on an add needed basis and wrap them in a using so they are disposed quickly, or should I create a static class similar to System.Drawing.Brushes class?
推荐答案
IMO,他们有足够的效率,你通常应该不会创建用于在多个方法调用长寿命的情况下,但足够低效率的,你应该创建的每个人们只要一旦特定方法中,而不是创建一个新的每次你需要画一些时间。
IMO, they're efficient enough that you should usually not create long-lived instances that are used over several method calls, but inefficient enough that you should create each one only once within a particular method, instead of creating a new one each time you need to draw something.
在换句话说,不存储自定义画笔在你的类,你用它来绘制的每个的OnPaint
打电话给你的文字,也没有创建新的刷的每一行文字的你,OnPaint中调用内画,无论是。
In other words, don't store a custom brush in your class that you use to paint your text on every OnPaint
call, but also don't create a new brush for every line of text you draw within that OnPaint call, either.
这篇关于指南用刷子和笔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!