KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > svggen > DrawImage


1 /*
2
3    Copyright 2001 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.svggen;
19
20 import java.awt.*;
21 import java.awt.geom.*;
22 import java.awt.image.*;
23
24 /**
25  * This test validates drawImage conversions.
26  *
27  * @author <a HREF="mailto:vhardy@eng.sun.com">Vincent Hardy</a>
28  * @version $Id: DrawImage.java,v 1.4 2004/08/18 07:16:44 vhardy Exp $
29  */

30 public class DrawImage implements Painter {
31     public void paint(Graphics2D g) {
32         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
33                            RenderingHints.VALUE_ANTIALIAS_ON);
34
35         // Create an Image
36
BufferedImage image = new BufferedImage(100, 75, BufferedImage.TYPE_INT_ARGB);
37         Graphics2D ig = image.createGraphics();
38         ig.scale(.5, .5);
39         ig.setPaint(new Color(128,0,0));
40         ig.fillRect(0, 0, 100, 50);
41         ig.setPaint(Color.orange);
42         ig.fillRect(100, 0, 100, 50);
43         ig.setPaint(Color.yellow);
44         ig.fillRect(0, 50, 100, 50);
45         ig.setPaint(Color.red);
46         ig.fillRect(100, 50, 100, 50);
47         ig.setPaint(new Color(255, 127, 127));
48         ig.fillRect(0, 100, 100, 50);
49         ig.setPaint(Color.black);
50         ig.draw(new Rectangle2D.Double(0.5, 0.5, 199, 149));
51         ig.dispose();
52
53         // drawImage(img,x,y,bgcolor,observer);
54
g.drawImage(image, 5, 10, Color.gray, null);
55         g.translate(150, 0);
56         
57         // drawImage(img,x,y,w,h,observer)
58
g.drawImage(image, 5, 10, 50, 40, null);
59         g.translate(-150, 80);
60         
61         // drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,observer);
62
g.drawImage(image, 5, 10, 45, 40, 50, 0, 100, 25, null);
63         g.translate(150, 0);
64         
65         // drawImage(img,dx1,dy1,dx2,dy2,sx1,sy1,sx2,sy2,bgcolor,observer);
66
g.drawImage(image, 5, 10, 45, 40, 50, 50, 100, 75, Color.gray, null);
67         g.translate(-150, 80);
68         
69         // drawImage(img,xform,obs)
70
AffineTransform at = new AffineTransform();
71         at.scale(.5, .3);
72         at.translate(5, 10);
73         g.drawImage(image, at, null);
74         
75         g.translate(150, 0);
76
77         // drawImage(img,op,x,y);
78
RescaleOp op = new RescaleOp(.5f, 0f, null);
79         g.drawImage(image,op,5,10);
80         
81         g.translate(-150, 0);
82
83         g.translate(0, 80);
84
85         // drawImage(x,y,w,y,bgcolor,observer)
86
g.drawImage(image, 5, 10, 50, 40, Color.gray, null);
87
88     }
89 }
90
Popular Tags