水印:
public void paint(Graphics g) {
// TODO 自动生成的方法存根
Graphics2D g2=(Graphics2D)g;
URL url=paint.class.getResource("qq.jpg");
Image img=Toolkit.getDefaultToolkit().getImage(url);
g2.drawImage(img, 0, 0, 400, 400, this);
int x=100;
int y=100;
String str=new String("mafeng");
Font font =new Font("华文行楷",Font.BOLD,72);
g2.setFont(font);
AlphaComposite al=AlphaComposite.SrcOver.derive(0.3f);
g2.setComposite(al);
g2.setColor(color);
g2.drawString(str, x, y);
System.out.println("456");
}
纹理填充特效:
public void paint(Graphics g) {
// TODO 自动生成的方法存根
BufferedImage bi=new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
Graphics2D g2=bi.createGraphics();
g2.setColor(Color.blue);
g2.fillOval(0, 0, 90, 90);
g2.setColor(Color.yellow);
g2.fillRect(70, 70, 80, 80);
Rectangle2D rect=new Rectangle2D.Float(10,10,20,20);
TexturePaint te=new TexturePaint(bi, rect);
Graphics2D gb2=(Graphics2D)g;
gb2.setPaint(te);
gb2.fillRect(0, 0, 400, 400);
}
图片半透明特效:
和水印原理是一样的
AlphaComposite al=AlphaComposite.SrcOver.derive(0.3f);
g2.setComposite(al);
以椭圆形显示图象:
public void paint(Graphics g) {
// TODO 自动生成的方法存根
Graphics2D g2=(Graphics2D)g;
URL url=paint.class.getResource("qq.jpg");
Image img=Toolkit.getDefaultToolkit().getImage(url);
g2.drawImage(img, 0, 0, 400, 400, this);
Rectangle2D.Float rect=new Rectangle2D.Float(0, 0, 400, 400);
Ellipse2D.Float ell=new Ellipse2D.Float(20, 20, 300, 250);
Area area1=new Area(rect);
Area area2=new Area(ell);
area1.subtract(area2);
g2.fill(area1);
}