ThinLineTest.java revision 2362
0N/A/*
0N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A */
0N/Aimport java.awt.*;
733N/Aimport java.awt.geom.Ellipse2D;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.io.File;
0N/Aimport javax.imageio.ImageIO;
0N/A
0N/A/**
0N/A * @author chrisn@google.com (Chris Nokleberg)
0N/A * @author yamauchi@google.com (Hiroshi Yamauchi)
0N/A */
0N/Apublic class ThinLineTest {
0N/A private static final int PIXEL = 381;
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
0N/A Graphics2D g = image.createGraphics();
0N/A
0N/A g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
0N/A g.setPaint(Color.WHITE);
0N/A g.fill(new Rectangle(image.getWidth(), image.getHeight()));
0N/A
0N/A g.scale(0.5 / PIXEL, 0.5 / PIXEL);
0N/A g.setPaint(Color.BLACK);
0N/A g.setStroke(new BasicStroke(PIXEL));
0N/A g.draw(new Ellipse2D.Double(PIXEL * 50, PIXEL * 50, PIXEL * 300, PIXEL * 300));
0N/A
0N/A // To visually check it
0N/A //ImageIO.write(image, "PNG", new File(args[0]));
0N/A
0N/A boolean nonWhitePixelFound = false;
0N/A for (int x = 0; x < 200; ++x) {
0N/A if (image.getRGB(x, 100) != Color.WHITE.getRGB()) {
0N/A nonWhitePixelFound = true;
0N/A break;
0N/A }
0N/A }
0N/A if (!nonWhitePixelFound) {
0N/A throw new RuntimeException("The thin line disappeared.");
0N/A }
0N/A }
0N/A}
0N/A