Path: blob/master/test/jdk/sun/java2d/marlin/StrokeShapeTest.java
41149 views
/*1* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.awt.*;23import java.awt.geom.Ellipse2D;24import java.awt.geom.GeneralPath;25import java.awt.image.BufferedImage;26import java.io.File;2728import javax.imageio.ImageIO;2930/**31* @author [email protected] (Chris Nokleberg)32* @author [email protected] (Hiroshi Yamauchi)33*/34public class StrokeShapeTest {35public static void main(String[] args) throws Exception {36BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);37Graphics2D g = image.createGraphics();38g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);39g.setPaint(Color.WHITE);40g.fill(new Rectangle(image.getWidth(), image.getHeight()));41g.translate(25, 100);4243Stroke stroke = new BasicStroke(200, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);44Shape shape = new Polygon(new int[] {0, 1500, 0}, new int[] {750, 0, -750}, 3);4546g.scale(.1, .1);47g.setPaint(Color.BLACK);48g.setStroke(stroke);49g.draw(shape);50g.setPaint(Color.RED);51g.fill(stroke.createStrokedShape(shape));5253// To visually check it54//ImageIO.write(image, "PNG", new File(args[0]));5556boolean blackPixelFound = false;57outer:58for (int x = 0; x < 200; ++x) {59for (int y = 0; y < 200; ++y) {60if (image.getRGB(x, y) == Color.BLACK.getRGB()) {61blackPixelFound = true;62break outer;63}64}65}66if (blackPixelFound) {67throw new RuntimeException("The shape hasn't been filled in red.");68}69}70}717273