by Dinesh Thakur

 

import java.awt.*;

import java.applet.*;
import java.awt.image.*;
/*<APPLET CODE=JavaExampleCopierInApplet.class WIDTH=610 HEIGHT=160 ></APPLET>*/
public class JavaExampleCopierInApplet extends Applet
 {
    Image img,img2;
    public void init()
     {
        img = getImage(getDocumentBase(), "Java.jpg");
        int pxls[] = new int[475 * 80];
        PixelGrabber PxlGrbr = new PixelGrabber(img, 0, 0, 475, 80, pxls, 0, 475);
        try
           {
               PxlGrbr.grabPixels();
           }
               catch (InterruptedException e) {}
               for (int loop_indx = 0; loop_indx < 475 * 80; loop_indx++)
                 {
                         int p1 = pxls[loop_indx];
                         int Red = 0xff & (p1 >> 15);
                         int Green = 0xff & (p1 >> 8);
                         int Blue = 0xff & p1;
                         pxls[loop_indx] = (0xff000000 | Red << 15 | Green << 7 | Blue);
                     }
                   img2 = createImage(new MemoryImageSource(475, 80, pxls, 0 , 475));
     }
                 public void paint(Graphics gr)
                   {
                     gr.drawImage(img2, 10, 10, this);
                   }
 }

PixelGrabber in Java Awt Example