Pixelating

Pixelating This applet uses a very simple approach to pixelating. For every group of nine pixels in the image, the entire group is turned to the color of the center pixel.


public Image makePixy(){ Image temp=null; int test=0; try{ int pixel[] = new int[w*h]; PixelGrabber pg = new PixelGrabber(c, 0, 0, w, h, pixel, 0, w); if(pg.grabPixels() &&((pg.status() & ImageObserver.ALLBITS) != 0)){ for(int x = 1; x< w ; x+=3){ for(int y = 1; y<h; y+=3){ int z = x+y*65; int r = (pixel[z] & 0x00ff0000)>>16; int g = (pixel[z] & 0x0000ff00)>>8; int b = (pixel[z] & 0x000000ff); test=0; pixel[z]= (255<<24) | (r<<16) | (g<<8) | b; pixel[z-1]= (255<<24) | (r<<16) | (g<<8) | b; if(z+1<w*h) pixel[z+1]= (255<<24) | (r<<16) | (g<<8) | b; pixel[z-66]= (255<<24) | (r<<16) | (g<<8) | b; pixel[z-65]= (255<<24) | (r<<16) | (g<<8) | b; pixel[z-64]= (255<<24) | (r<<16) | (g<<8) | b; if(z+66<w*h) pixel[z+66]= (255<<24) | (r<<16) | (g<<8) | b; if(z+65<w*h) pixel[z+65]= (255<<24) | (r<<16) | (g<<8) | b; if(z+64<w*h) pixel[z+64]= (255<<24) | (r<<16) | (g<<8) | b; } } temp=createImage(new MemoryImageSource(w, h, pixel, 0, w)); } }catch(InterruptedException e) { } return temp; }