Trying to paint to screen a bit array fast

Im trying to create a smaller memory footprint of black and white tiff images. When I load them with the imageio extension they come out huge as a buffered image. Anyhow, I store them as 2D bit arrays for black and white. Im trying to print these 2D bit arrays, but they paint slow if I go pixel by pixel. Is there a way to paint something to screen at once without having to paint it into an image first?

[412 byte] By [studmaniea] at [2007-10-3 9:27:09]
# 1
Whats the difference between painting to an image and painting on the screen? They should come out the same.
CaptainMorgan08a at 2007-7-15 4:41:29 > top of Java-index,Security,Cryptography...
# 2

Either way is fine, but a method to paint it quickly. I painted to an image and painted the image and ive painted directly to screen. The problem I have it actually painting it with the Graphics2D object. It takes a long time to read a line of pixels and paint it. I actually use the drawline method. Is there a faster way instead of calling so many paint operations? Its really slow drawing it out

studmaniea at 2007-7-15 4:41:29 > top of Java-index,Security,Cryptography...
# 3
Paint it to an Image. Then in your paint method, use the drawImage() method.
CaptainMorgan08a at 2007-7-15 4:41:29 > top of Java-index,Security,Cryptography...
# 4
I did that. The display isnt the slow part, that painting is. So when I paint to an image its slow. I have to traverse the pixels and paint them. Is there a quicker way to do this?
studmaniea at 2007-7-15 4:41:29 > top of Java-index,Security,Cryptography...
# 5

Heres the code I use:

private int bitpos[] = {1,2,4,8,16,32,64,128};

private VolatileImage renderBitImage(bitimage mybit){

VolatileImage dbImage = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleVolatileImage(mybit.getWidth(), mybit.getHeight());

Graphics2D dbg;

if (dbImage == null) {

System.out.println("dbImage is null");

return null;

}

else{

dbg = (Graphics2D)dbImage.getGraphics();

dbg.setColor(Color.BLUE);

dbg.fillRect(0, 0, mybit.getWidth(), mybit.getHeight());

//draw a line along the x

int linestart = 0;

int lineend = 0;

boolean inblack = false;

dbg.setColor(Color.WHITE);

//dbg.drawLine(0,10,200,10);

for(int y = 0; y < mybit.getHeight(); ++y){

for(int x = 0; x < mybit.getWidth(); ++x){

if(is_black(x,y,mybit.getImage())){

if(!inblack){

inblack = true;

linestart = x;

}

} else{

if(inblack){

inblack = false;

lineend = x - 1;

dbg.drawLine(linestart,y,lineend,y);

//System.out.println("Drawing a line " + linestart + "," + y + "," + lineend + "," + y);

}

}

}

if(inblack){

inblack = false;

lineend = mybit.getWidth() - 1;

dbg.drawLine(linestart,y,lineend,y);

//System.out.println("Drawing a line " + linestart + "," + y + "," + lineend + "," + y);

}

}

return dbImage;

}

}

private boolean is_black(int x, int y, int buf[][]){

try{

int mybyte = buf[(int)((double)x/8d)][y];

if((mybyte & bitpos[x%8]) == bitpos[x%8]) return true;

else return false;

}

catch(Exception e){

e.printStackTrace();

return false;

}

}

bitimage is a class that hold the width and height in int for the image and a 2D array of the on/off bits(int[][]).

studmaniea at 2007-7-15 4:41:29 > top of Java-index,Security,Cryptography...