public static void drawImageClip(Graphics g,BufferedImage image,ImageObserver observer){
  Rectangle clip=g.getClipBounds();
  if (clip != null) {
    int w=image.getWidth();
    int h=image.getHeight();
    int x=Math.max(0,Math.min(clip.x,w));
    int y=Math.max(0,Math.min(clip.y,h));
    w=Math.min(clip.width,w - x);
    h=Math.min(clip.height,h - y);
    if (w > 0 && h > 0) {
      g.drawImage(image.getSubimage(x,y,w,h),clip.x,clip.y,observer);
    }
  }
 else {
    g.drawImage(image,0,0,observer);
  }
}

public static void drawImageClip ( Graphics g , BufferedImage image , ImageObserver observer ) { Rectangle clip = g . getClipBounds ( ) ; if ( clip != null ) { int w = image . getWidth ( ) ; int h = image . getHeight ( ) ; int x = Math . max ( 0 , Math . min ( clip . x , w ) ) ; int y = Math . max ( 0 , Math . min ( clip . y , h ) ) ; w = Math . min ( clip . width , w - x ) ; h = Math . min ( clip . height , h - y ) ; if ( w > 0 && h > 0 ) { g . drawImage ( image . getSubimage ( x , y , w , h ) , clip . x , clip . y , observer ) ; } } else { g . drawImage ( image , 0 , 0 , observer ) ; } }
draws the image inside the clip bounds to the given graphics object .
