3008
|
1 |
/*
|
|
2 |
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
import java.awt.*;
|
|
25 |
import java.awt.geom.Ellipse2D;
|
|
26 |
import java.awt.image.BufferedImage;
|
|
27 |
import java.io.File;
|
|
28 |
import javax.imageio.ImageIO;
|
|
29 |
|
|
30 |
|
|
31 |
public class ScaleTest {
|
|
32 |
public static void main(String[] args) throws Exception {
|
|
33 |
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
|
|
34 |
Graphics2D g = image.createGraphics();
|
|
35 |
|
|
36 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
37 |
g.setPaint(Color.WHITE);
|
|
38 |
g.fill(new Rectangle(image.getWidth(), image.getHeight()));
|
|
39 |
g.scale(.9, .9);
|
|
40 |
g.setPaint(Color.BLACK);
|
|
41 |
g.setStroke(new BasicStroke(0.5f));
|
|
42 |
g.draw(new Ellipse2D.Double(25, 25, 150, 150));
|
|
43 |
|
|
44 |
// To visually check it
|
|
45 |
//ImageIO.write(image, "PNG", new File(args[0]));
|
|
46 |
|
|
47 |
boolean nonWhitePixelFound = false;
|
|
48 |
for (int x = 100; x < 200; ++x) {
|
|
49 |
if (image.getRGB(x, 90) != Color.WHITE.getRGB()) {
|
|
50 |
nonWhitePixelFound = true;
|
|
51 |
break;
|
|
52 |
}
|
|
53 |
}
|
|
54 |
if (!nonWhitePixelFound) {
|
|
55 |
throw new RuntimeException("A circle is rendered like a 'C' shape.");
|
|
56 |
}
|
|
57 |
}
|
|
58 |
}
|