Search in sources :

Example 66 with Color

use of java.awt.Color in project jdk8u_jdk by JetBrains.

the class MultiResolutionRenderingHintsTest method main.

public static void main(String[] args) throws Exception {
    int length = COLORS.length;
    BufferedImage[] resolutionVariants = new BufferedImage[length];
    for (int i = 0; i < length; i++) {
        resolutionVariants[i] = createRVImage(getSize(i), COLORS[i]);
    }
    BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage(resolutionVariants);
    // base
    Color color = getImageColor(VALUE_RESOLUTION_VARIANT_BASE, mrImage, 2, 3);
    if (!getColorForScale(1).equals(color)) {
        throw new RuntimeException("Wrong base resolution variant!");
    }
    // dpi fit
    color = getImageColor(VALUE_RESOLUTION_VARIANT_DPI_FIT, mrImage, 2, 3);
    if (!getColorForScale(2).equals(color)) {
        throw new RuntimeException("Resolution variant is not based on dpi!");
    }
    // size fit
    color = getImageColor(VALUE_RESOLUTION_VARIANT_SIZE_FIT, mrImage, 2, 3);
    if (!getColorForScale(6).equals(color)) {
        throw new RuntimeException("Resolution variant is not based on" + " rendered size!");
    }
    // default
    // depends on the policies of the platform
    // just check that exception is not thrown
    getImageColor(VALUE_RESOLUTION_VARIANT_DEFAULT, mrImage, 2, 3);
}
Also used : BaseMultiResolutionImage(java.awt.image.BaseMultiResolutionImage) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage)

Example 67 with Color

use of java.awt.Color in project jdk8u_jdk by JetBrains.

the class MlibOpsTest method createSrcImage.

private static BufferedImage createSrcImage() {
    BufferedImage img = createImage();
    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = { 0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
    RadialGradientPaint p = new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();
    return img;
}
Also used : Point2D(java.awt.geom.Point2D) Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 68 with Color

use of java.awt.Color in project jdk8u_jdk by JetBrains.

the class ReadAsGrayTest method verify.

private static void verify(BufferedImage src, BufferedImage dst, ImageTypeSpecifier type) {
    BufferedImage test = type.createBufferedImage(src.getWidth(), src.getHeight());
    Graphics2D g = test.createGraphics();
    g.drawImage(src, 0, 0, null);
    g.dispose();
    for (int i = 0; i < colors.length; i++) {
        int x = i * dx + dx / 2;
        int y = h / 2;
        Color c_test = new Color(test.getRGB(x, y));
        Color c_dst = new Color(dst.getRGB(x, y));
        if (!compareWithTolerance(c_test, c_dst, 0.01f)) {
            String msg = String.format("Invalid color: %x instead of %x", c_dst.getRGB(), c_test.getRGB());
            throw new RuntimeException("Test failed: " + msg);
        }
    }
    System.out.println("Verified.");
}
Also used : Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 69 with Color

use of java.awt.Color in project jdk8u_jdk by JetBrains.

the class JPEGsNotAcceleratedTest method writeTestImage.

public static void writeTestImage(String fileName) {
    BufferedImage bi = new BufferedImage(TEST_W, TEST_H, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    g.setColor(new Color(testRGB));
    g.fillRect(0, 0, TEST_W, TEST_H);
    try {
        System.err.printf("Writing %s\n", fileName);
        if (lowCompression) {
            ImageWriter iw = (ImageWriter) ImageIO.getImageWritersBySuffix("jpeg").next();
            if (iw == null) {
                throw new RuntimeException("No available image writer for " + "jpeg " + " Test failed.");
            }
            File file = new File(fileName);
            ImageOutputStream ios = ImageIO.createImageOutputStream(file);
            iw.setOutput(ios);
            ImageWriteParam param = iw.getDefaultWriteParam();
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            param.setCompressionQuality(1);
            IIOImage iioImg = new IIOImage(bi, null, null);
            iw.write(null, iioImg, param);
        } else {
            ImageIO.write(bi, "jpeg", new File(fileName));
        }
    } catch (IOException e) {
        System.err.println("Error " + e + " when writing file: " + fileName);
        throw new RuntimeException(e);
    }
}
Also used : Graphics(java.awt.Graphics) Color(java.awt.Color) ImageWriter(javax.imageio.ImageWriter) IOException(java.io.IOException) ImageWriteParam(javax.imageio.ImageWriteParam) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) ImageOutputStream(javax.imageio.stream.ImageOutputStream) IIOImage(javax.imageio.IIOImage)

Example 70 with Color

use of java.awt.Color in project jdk8u_jdk by JetBrains.

the class WritingInterruptionTest method createTestImage.

private static BufferedImage createTestImage() {
    int w = 1024;
    int h = 768;
    BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    Color[] colors = { Color.red, Color.green, Color.blue };
    float[] dist = { 0.0f, 0.5f, 1.0f };
    Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
    RadialGradientPaint p = new RadialGradientPaint(center, 0.5f * w, dist, colors);
    g.setPaint(p);
    g.fillRect(0, 0, w, h);
    g.dispose();
    return img;
}
Also used : Point2D(java.awt.geom.Point2D) Color(java.awt.Color) RadialGradientPaint(java.awt.RadialGradientPaint) RadialGradientPaint(java.awt.RadialGradientPaint) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

Color (java.awt.Color)2973 Graphics2D (java.awt.Graphics2D)396 Font (java.awt.Font)250 BufferedImage (java.awt.image.BufferedImage)236 Dimension (java.awt.Dimension)193 JPanel (javax.swing.JPanel)193 Point (java.awt.Point)188 BasicStroke (java.awt.BasicStroke)177 ArrayList (java.util.ArrayList)173 Test (org.junit.Test)156 JLabel (javax.swing.JLabel)148 Paint (java.awt.Paint)140 Rectangle (java.awt.Rectangle)109 GradientPaint (java.awt.GradientPaint)108 Insets (java.awt.Insets)103 GridBagConstraints (java.awt.GridBagConstraints)96 IOException (java.io.IOException)96 Stroke (java.awt.Stroke)94 JScrollPane (javax.swing.JScrollPane)93 File (java.io.File)89