import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
import java.io.*;
import java.awt.font.*;

public class MyClipping {
	

	
	
	
	public static void main (String[] args) {
		
		//Fenster erzeugen
		MyFrame frame = new MyFrame( "7624", 800,600 ) 
		{
			protected BufferedImage loadTheImage() 
			{
				BufferedImage img=null;
				
				try {
					String dateiname=new String("urlaub.jpg");
					FileInputStream in = new FileInputStream( dateiname );
					JPEGImageDecoder decoder= JPEGCodec.createJPEGDecoder(in);
					img = decoder.decodeAsBufferedImage();
					in.close();
				}
				catch( Exception e )
				{System.out.print(e);}		
				
				return img;
			}			
			public void paint(Graphics g) {
				//Upcast --> mehr Funktionen in Graphics2D
				Graphics2D g2d=(Graphics2D)g;
				g2d.setRenderingHint( 	RenderingHints.KEY_ANTIALIASING,
							RenderingHints.VALUE_ANTIALIAS_ON
						);
				
				//ein schönes Bild laden
				BufferedImage img=loadTheImage(); 

				//Schrift erzeugen
				Font f = new Font("Arial",Font.ITALIC|Font.BOLD,260);
				
				//Umriß eines Strings als GlyphVector speichern
				GlyphVector gv = f.createGlyphVector( 
							g2d.getFontRenderContext()
							, "Enjoy");
				
				//Hintergrund schwarz
				g2d.fill( new Rectangle2D.Float(0,0,800,600) );
				
				//Clipping Shape von GlyphVector holen
				Shape clipping_shape = gv.getOutline();
				
				//Clipping Shape soll bei (0,0) beginnen
				g2d.translate( 	-clipping_shape.getBounds().getX(),
						-clipping_shape.getBounds().getY()
						);
				//jetzt Clipping Shape horizontal und vertikal zentrieren
				g2d.translate( 	400-clipping_shape.getBounds().getWidth()/2,
						300-clipping_shape.getBounds().getHeight()/2+50 );
				
				g2d.scale( 1, 1.4 );//Clipping Shape skalieren...
				g2d.setClip( clipping_shape );//und setzen
			
				//das Bild zentriert malen (OHNE Transformation)
				g2d.setTransform( new AffineTransform() );
				g2d.drawImage(img, null, 400-img.getWidth()/2,
						300-img.getHeight()/2);
			}
		};
	}
}		
		

