no repaint while resizing when using .setPaint(gradient)

可紊 提交于 2019-12-02 03:08:35

I put together a test and found that the GradientPaint has woeful performance. Taking an average render time from 1.2 seconds (at 400x400 pixles) out to 20+ seconds.

I changed the GradientPaint for a LinearGradientPaint and found that the render time was around 1.3 seconds instead.

LinearGradientPaint lgp = new LinearGradientPaint(
                new Point2D.Float(0, minY),
                new Point2D.Float(0, maxY),
                new float[] {0f, 0.5f, 1f},
                new Color[] {Color.BLUE, Color.RED, Color.BLUE}
                );
g2d.setPaint(lgp);
    // Render all your samples, don't reapply or change you paint...

Sorry, my sample isn't very exciting...

You may find it better to render to a backing buffer in a background thread instead and paint the whole image to the screen once it's complete. This will stop the screen from becoming "paused"

If this is an applet, put that thing in

public void start()
{
}

and

public void stop()
{
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!