473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Fast rectangle filling


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

Jul 17 '05 #1
2 5858
Why is fillRect so slow? Because this is java (-_-)

"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

Jul 17 '05 #2


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?

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: qumpus | last post by:
My program right now generates USPS style shipping label using System.Drawing.Graphics. It works fine except that the printer prints really slowly. I want to make my program take advantage of true...
15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
3
by: | last post by:
I am having a hard time understanding the logic behind the Rectangle object. My problem has to do with the way the rectangle treats the "Width" property. For example, take the following rectangle...
6
by: Brad Shook | last post by:
Can someone point me to an example or post some code on how to allow a user to draw a rectangle on top of an image and retrieve the coordinates and dimensions of it. They will also need to be able...
1
by: Morten Snedker | last post by:
Hey folks, I'm trying to make my own progressbar. The idea (for my test) is a rectangle that is 1/60 filled with a color per second (so after a minute it is all filled). This is what I have...
5
by: DazedAndConfused | last post by:
I have a rectangle around text that I want to fill in with color. I do not know the height of the rectangle until I actually go through and draw out the text. Is there a way of filling in the...
4
by: RobinS | last post by:
I am drawing a rectangle on a picture that has already been drawn on the graphics area (a user control). It works something like this: //in the MouseDown event m_isDragging = true; m_oldX =...
4
by: Ty | last post by:
Hi all Short version of my problem: i have a Datagrid (Flexgrid from ComponentOne) with a Datatable as source. I need to search a row in the datatable, using a primary key column in the...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.