/* * Created on 2004/04/30 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package zoom2; import java.awt.Image; import java.awt.image.ImageProducer; import java.awt.image.MemoryImageSource; import java.awt.Component; import java.awt.image.PixelGrabber; /** * @author kaji * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class PxlImage extends Component { private boolean cond=false; protected int srcW,srcH,_widt,_heig; protected int pxls[],cp_pxls[]; public Image CroppedImage; public PxlImage(Image img) { srcW=img.getWidth(null); srcH=img.getHeight(null); if ((srcW<1)||(srcH<1)) { return; } pxls=new int[srcW*srcH]; PixelGrabber pg= new PixelGrabber(img,0,0,srcW,srcH,pxls,0,srcW); try { pg.grabPixels(); } catch (InterruptedException e) { e.printStackTrace(); return; } } public Image crop(int x,int y,int widt,int heig) { Image tmp; ImageProducer ip=new MemoryImageSource(widt,heig,pxls, srcW*y+x,srcW); tmp=createImage(ip); return(tmp); } public void create_cropBuffer(int w,int h) { int i; cp_pxls=new int[w*h]; for (i=0;i<(w*h);i++) cp_pxls[i]=0; _widt=w; _heig=h; ImageProducer ip=new MemoryImageSource(w,h,cp_pxls, 0,w); CroppedImage=createImage(ip); return; } public void copyto_cropBuffer(int x,int y,int step) { int i,j,dest,idx; dest=0; for (j=0;j<_heig;j++) { for (i=0;i<_widt;i++) { idx=((y+(j*step))*srcW)+x+(i*step); if (idx>=(srcW*srcH)) return; if ((x+i)>=srcW) cp_pxls[dest]=0; else cp_pxls[dest]=pxls[idx]; dest++; } } } public Image get_croppedImage(int x,int y) { copyto_cropBuffer(x,y,1); CroppedImage.flush(); return(CroppedImage); } public Image get_croppedImage_stepby(int x,int y,int step) { copyto_cropBuffer(x,y,step); CroppedImage.flush(); return(CroppedImage); } public Image flush_and_get() { CroppedImage.flush(); return(CroppedImage); } }