[java] pixelGrabber and grabPixels

Started by
1 comment, last by ao 23 years, 7 months ago
I have a background image where I draw all my graphics too, I would like to grab all the pixels of that background image and put them into an array so I can manipulate them. Now, the problem is grabPixels only works the first time I call it, after that it doesn''t grab pixels. It only works if I do this every loop: pg = new PixelGrabber( backBuffer, 0, 0, 320, 240, bbPixels, 0, 320 ); try { pg.grabPixels(); } catch( InterruptedException ie ) { System.out.println( "Couldn''t grab em" ); } I really don''t want to create a new PixelGrabber object every time through the loop, it is slow... Shouldn''t subsequent calls to grabPixels work and refill the bbPixels array with the current data? Thanks, ao
Play free Java games at: www.infinitepixels.com
Advertisement
quote: Original post by ao
Shouldn't subsequent calls to grabPixels work and refill the bbPixels array with the current data?



That is what happens, although sometimes you have to wait for the Image to send all its pixels.

try {     if ( ! pg.grabPixels() ) {          System.out.println("Grab aborted");          return;     }} catch (InterruptedException e) {     System.out.println("Grab Timed out: \n" + e.printStackTrace());}  



Edited by - Jim_Ross on September 21, 2000 11:52:52 AM
Well, ya see, thats the strange thing. I checked the return value of pg.grabPixels() it is true... And according to the documentation that means:

Returns:
true if the pixels were successfully grabbed, false on abort, error or timeout

Well, I know the pixels weren''t successfully grabbed. Because an image that I drew on the backbuffer just before calling grabPixels isn''t there. But it does appear ( in the bbPixel array ) if I put the:

pg = new PixelGrabber( backBuffer, 0, 0, 320, 240, bbPixels, 0, 320 );

code in there. So I know the data is there, grabPixels just isn''t grabbing it.

hmmmm,
ao
Play free Java games at: www.infinitepixels.com

This topic is closed to new replies.

Advertisement