• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# [java] pixelGrabber and grabPixels

## 2 posts in this topic

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
0

##### Share on other sites
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
0

##### Share on other sites
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
0

• 14
• 12
• 11
• 18
• 19