码迷,mamicode.com
首页 > 其他好文 > 详细

图片特效

时间:2015-04-27 23:36:52      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

水印:

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);

}

 

图片特效

标签:

原文地址:http://www.cnblogs.com/mafeng/p/4461683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!