Hello all, I am new here and fairly new to java and programming in general. I decided to make a little color chooser hoojie for fun (jar file attached), but it is tremendously slow. Partly it is my fault (code def not perfect..) but when I checked what was taking so long it was pretty clear that the calls to paint were the real bottleneck.
Basically, I am painting each pixel independently using g.fillRect(x,y,1,1) along with a bunch of linear algebra/geometry. This does not seem very elegant, so I tried again by painting the same stuff onto a VolatileImage and then painting the image onto the on-screen panel (thinking that it was the on-screen paint calls that were slowing it all up) but that made no real difference.
What am I missing here? Ideally what I would like is take (and assuming that getColors() returns a well-formed array[][])
Color[][] colors = getColors();
for(int i=0; i<colors.length; i++) for(int j=0; j<colors[0].length; j++){
g.setColor(colors[i][j]);
g.fillRect(i,j,1,1);
}
and replace it with something approaching the following
int firstPixelX=0;
int firstPixelY=0;
g.paintPixels(firstPixelX,firstPixelY,colors);
I know that this is not an option, but I also know that there's a lot I don't know.. So, if anyone has good suggestions I would be very grateful.
Thank you