Phil... wrote:
Why is fillRect so slow? Because this is java (-_-)
Okay, that's a singularly unhelpful answer. Topposted, too :P
"Mark McKay" <ma**@kitfox.com> wrote in message
news:fl********************@mantis.golden.net...
I have an application that needs to quickly draw solid rectangles of
uniform color on Images and VolitileImages. I was surprised in a recent
benchmark to find that Graphics.fillRect(x1, y1, x2, y2) was slower than
Graphics.drawImage() (I was copying rectangular subregions of a larger
image without scaling).
Why is fillRect so slow? What's the best way to clear a rectangle to a
single solid color? Also, what's the best way to clear a rectangle to
be the completely transparent color?
Mark McKay
--
http://www.kitfox.com
I imagine fillRect is so slow because most interpreters know how to
accelerate drawImage through either DirectDraw or what-have-you.native
method. fillRect actually uses Java to accomplish what it does, so it's
not as helpful. *sigh*.
Best way to clear a rectangle to a single solid color?
BufferedImage red = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);
red.getGraphics().setColor(Color.red);
red.getGraphics().fillRect(0, 0, x, y);
....
g.drawImage(red, 0, 0, comp);
// where x and y are arbitrary ints, and comp is an arbitrary Component
To a clear color, well, I dunno. Never tried before.
I suppose you might try BufferedImage.TYPE_INT_ARGB, and a perfectly
transparent color. But then again, I don't know if that will work or not.
I used to know how to make Applet's mimic their web page's background
color, but I forget, now. Anyone else know?