Java - 自定义油漆声明性能
快速是,不是,或者这并不重要:
我正在重写抽象按钮的绘制方法,我想知道这样做
GradientPaint gp = new GradientPaint(0, 0, color1, 0, h, color2);
RoundRectangle2D r = new RoundRectangle2D.Float(0, 0, w, h, w/5, h/5);
和类似的方法是否会影响性能与
GradientPaint gp;
RoundRectangle2D r;
外部绘制然后
gp = new GradientPaint(0, 0, color1, 0, h, color2);
r = new RoundRectangle2D.Float(0, 0, w, h, w/5, h/5);
在绘制方法内部的性能
Quick yes, no, or it doesn't really matter:
I'm overriding the paint method for an abstract button and I'm wondering if doing
GradientPaint gp = new GradientPaint(0, 0, color1, 0, h, color2);
RoundRectangle2D r = new RoundRectangle2D.Float(0, 0, w, h, w/5, h/5);
and similar methods are going to affect performance vs
GradientPaint gp;
RoundRectangle2D r;
outside paint and then
gp = new GradientPaint(0, 0, color1, 0, h, color2);
r = new RoundRectangle2D.Float(0, 0, w, h, w/5, h/5);
inside the paint method
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
杰里米怎么样了?
不是你要问的,但最快的可能是在 BufferedImage 中绘制一次,然后在 Paint (或者可能更好的 PaintComponent)方法中显示 BufferedImage。
How's it going Jeremy?
Not what you're asking, but quickest of all would likely be to do the drawing once in a BufferedImage, and then display the BufferedImage in the paint (or perhaps better paintComponent) method.
实例化它们一次或在必要时(例如大小更改)而不是多次。
Instantiate them once or when necessary (e.g. size change) rather than many times.
寻求最可维护的解决方案,直到你衡量问题:-)
每个“优化”都需要额外的逻辑(又名:LOC)。每增加一条线路都有一个难以预测的维护成本。我的一般规则是不会增加无法计算的成本。
顺便说一句:无论如何你都不能做你的第一个选择,渐变是不可变的 - 所以你必须在每次大小改变时重新创建。
Go for the most maintainable solution until you measure problems :-)
Every "optimization" requires additional logic (aka: LOC). Each additional line has a - difficult to predict - price in maintenance. My general rule it not add uncalculatable costs.
BTW: you can't do your first option anyway, gradients are immutable - so you have to recreate each time the size has changed.