How to do per pixel manipulation?

Hi all!
I have been on a “break” from java programing for quite some time, when i did stuff last time it was java 1.1 and to do per pixel manipulation i stored the images as byte arrays, so I could eaily manipulte colors, rotate, resize and such.

Now i have been thinking of getting up to date here, and would like to have input on how to do those thing in java 1.4 and/or 1.5.

An example of a old java 1.1 intro can be seen here http://joc.facelesswarriors.com/ . I would like to be able to do simular things like that but in the new java versions, and hopefully get better speed. :wink:

Warning applet take very long time to intitalize

No reply…hmm

Here is some old cod that might clear up what I mean :slight_smile:


/*Screen setup */
// create a double buffer
DoubleBufferImage=createImage(width,height);
DoubleBufferGraphics=DoubleBufferImage.getGraphics();

TargetPixelsTemp=new int[width*height];//clear buffer
TargetPixels=new int[width*height];
TargetCM=new DirectColorModel(32,0x00FF0000,0x000FF00,0x000000FF,0);

// create MemoryImageSource
TargetMIS=new MemoryImageSource(width,height,TargetCM,TargetPixels,0,width);
TargetMIS.setAnimated(true);
TargetMIS.setFullBufferUpdates(true);
.
.
.
.
/*Image to array*/
Image rk = getImage(getCodeBase(),"images/joc.gif");
logopix = new int[90*15];
PixelGrabber pg = new PixelGrabber(rk, 0, 0, 90, 15, logopix, 0, 90);
try { pg.grabPixels(); } catch (InterruptedException e) {}
.
.
.
/*And so on */


Did it help :stuck_out_tongue:

Anyway, I dont think this os how to do things nowdays, so some pointers to the fastest way to do stuff like this would be very much appreciated. I do still want to be able to have per pixel access for setting colors and other stuff.

Have a look at the Software rendering to a Canvas thread.

Create a BufferedImage. Then write directly to the int[] color buffer you get by the following code:

colorBuffer =  
  ((DataBufferInt) bufferedImage.getRaster().getDataBuffer()).getData();