Java Code Examples for sun.java2d.SunGraphics2D#setRenderingHint()

The following examples show how to use sun.java2d.SunGraphics2D#setRenderingHint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiResolutionDrawImageWithTransformTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static Color getImageColor(Image image, double configScale,
        double transformScale) {

    TestSurfaceData surface = new TestSurfaceData(SCREEN_SIZE, SCREEN_SIZE,
            configScale);
    SunGraphics2D g2d = new SunGraphics2D(surface,
            Color.BLACK, Color.BLACK, null);
    g2d.setRenderingHint(KEY_RESOLUTION_VARIANT,
            VALUE_RESOLUTION_VARIANT_SIZE_FIT);
    AffineTransform tx = AffineTransform.getScaleInstance(transformScale,
            transformScale);
    g2d.drawImage(image, tx, null);
    g2d.dispose();

    int backgroundX = (int) (1.5 * image.getWidth(null) * transformScale);
    int backgroundY = (int) (1.5 * image.getHeight(null) * transformScale);
    Color backgroundColor = surface.getColor(backgroundX, backgroundY);
    //surface.show(String.format("Config: %f, transform: %f", configScale, transformScale));
    if (!BACKGROUND_COLOR.equals(backgroundColor)) {
        throw new RuntimeException("Wrong background color!");
    }
    return surface.getColor(IMAGE_SIZE / 4, IMAGE_SIZE / 4);
}
 
Example 2
Source File: MultiResolutionDrawImageWithTransformTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static Color getImageColor(Image image, double configScale,
        double transformScale) {

    TestSurfaceData surface = new TestSurfaceData(SCREEN_SIZE, SCREEN_SIZE,
            configScale);
    SunGraphics2D g2d = new SunGraphics2D(surface,
            Color.BLACK, Color.BLACK, null);
    g2d.setRenderingHint(KEY_RESOLUTION_VARIANT,
            VALUE_RESOLUTION_VARIANT_SIZE_FIT);
    AffineTransform tx = AffineTransform.getScaleInstance(transformScale,
            transformScale);
    g2d.drawImage(image, tx, null);
    g2d.dispose();

    int backgroundX = (int) (1.5 * image.getWidth(null) * transformScale);
    int backgroundY = (int) (1.5 * image.getHeight(null) * transformScale);
    Color backgroundColor = surface.getColor(backgroundX, backgroundY);
    //surface.show(String.format("Config: %f, transform: %f", configScale, transformScale));
    if (!BACKGROUND_COLOR.equals(backgroundColor)) {
        throw new RuntimeException("Wrong background color!");
    }
    return surface.getColor(IMAGE_SIZE / 4, IMAGE_SIZE / 4);
}
 
Example 3
Source File: MultiResolutionRenderingHintsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Color getImageColor(final Object renderingHint, Image image,
        double configScale, double graphicsScale) {

    int width = image.getWidth(null);
    int height = image.getHeight(null);

    TestSurfaceData surface = new TestSurfaceData(width, height, configScale);
    SunGraphics2D g2d = new SunGraphics2D(surface,
            Color.BLACK, Color.BLACK, null);
    g2d.setRenderingHint(KEY_RESOLUTION_VARIANT, renderingHint);
    g2d.scale(graphicsScale, graphicsScale);
    g2d.drawImage(image, 0, 0, null);
    g2d.dispose();
    return surface.getColor(width / 2, height / 2);
}
 
Example 4
Source File: MultiResolutionRenderingHintsTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Color getImageColor(final Object renderingHint, Image image,
        double configScale, double graphicsScale) {

    int width = image.getWidth(null);
    int height = image.getHeight(null);

    TestSurfaceData surface = new TestSurfaceData(width, height, configScale);
    SunGraphics2D g2d = new SunGraphics2D(surface,
            Color.BLACK, Color.BLACK, null);
    g2d.setRenderingHint(KEY_RESOLUTION_VARIANT, renderingHint);
    g2d.scale(graphicsScale, graphicsScale);
    g2d.drawImage(image, 0, 0, null);
    g2d.dispose();
    return surface.getColor(width / 2, height / 2);
}