by Dinesh Thakur Category: AWT and Applets

 

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

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content





Popular Article