test/jdk/sun/pisces/ThinLineTest.java
changeset 47919 66350f079368
parent 47918 a82c9f231737
parent 47880 bbd692ad4fa3
child 47920 52c9e8d2f8d9
child 48093 2cb07c3778e1
equal deleted inserted replaced
47918:a82c9f231737 47919:66350f079368
     1 /*
       
     2  * Copyright (c) 2009, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 import java.awt.*;
       
    24 import java.awt.geom.Ellipse2D;
       
    25 import java.awt.image.BufferedImage;
       
    26 import java.io.File;
       
    27 import javax.imageio.ImageIO;
       
    28 
       
    29 /**
       
    30  * @author chrisn@google.com (Chris Nokleberg)
       
    31  * @author yamauchi@google.com (Hiroshi Yamauchi)
       
    32  */
       
    33 public class ThinLineTest {
       
    34   private static final int PIXEL = 381;
       
    35 
       
    36   public static void main(String[] args) throws Exception {
       
    37     BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
       
    38     Graphics2D g = image.createGraphics();
       
    39 
       
    40     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
       
    41     g.setPaint(Color.WHITE);
       
    42     g.fill(new Rectangle(image.getWidth(), image.getHeight()));
       
    43 
       
    44     g.scale(0.5 / PIXEL, 0.5 / PIXEL);
       
    45     g.setPaint(Color.BLACK);
       
    46     g.setStroke(new BasicStroke(PIXEL));
       
    47     g.draw(new Ellipse2D.Double(PIXEL * 50, PIXEL * 50, PIXEL * 300, PIXEL * 300));
       
    48 
       
    49     // To visually check it
       
    50     //ImageIO.write(image, "PNG", new File(args[0]));
       
    51 
       
    52     boolean nonWhitePixelFound = false;
       
    53     for (int x = 0; x < 200; ++x) {
       
    54       if (image.getRGB(x, 100) != Color.WHITE.getRGB()) {
       
    55         nonWhitePixelFound = true;
       
    56         break;
       
    57       }
       
    58     }
       
    59     if (!nonWhitePixelFound) {
       
    60       throw new RuntimeException("The thin line disappeared.");
       
    61     }
       
    62   }
       
    63 }