Example usage for java.awt RenderingHints VALUE_INTERPOLATION_NEAREST_NEIGHBOR

List of usage examples for java.awt RenderingHints VALUE_INTERPOLATION_NEAREST_NEIGHBOR

Introduction

In this page you can find the example usage for java.awt RenderingHints VALUE_INTERPOLATION_NEAREST_NEIGHBOR.

Prototype

Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR

To view the source code for java.awt RenderingHints VALUE_INTERPOLATION_NEAREST_NEIGHBOR.

Click Source Link

Document

Interpolation hint value -- the color sample of the nearest neighboring integer coordinate sample in the image is used.

Usage

From source file:lucee.runtime.img.Image.java

public void resizeImage(int width, int height, int interpolation) throws ExpressionException {
    Object ip;//from w w w  .j ava 2 s  .co  m
    if (interpolation == IPC_NEAREST)
        ip = RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
    else if (interpolation == IPC_BICUBIC)
        ip = RenderingHints.VALUE_INTERPOLATION_BICUBIC;
    else if (interpolation == IPC_BILINEAR)
        ip = RenderingHints.VALUE_INTERPOLATION_BILINEAR;
    else
        throw new ExpressionException("invalid interpoltion definition");

    BufferedImage dst = new BufferedImage(width, height, image().getType());
    Graphics2D graphics = dst.createGraphics();
    graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, ip);
    graphics.drawImage(image(), 0, 0, width, height, null);
    graphics.dispose();
    image(dst);

}

From source file:org.apache.pdfbox.rendering.PageDrawer.java

@Override
public void drawImage(PDImage pdImage) throws IOException {
    Matrix ctm = getGraphicsState().getCurrentTransformationMatrix();
    AffineTransform at = ctm.createAffineTransform();

    if (!pdImage.getInterpolate()) {
        boolean isScaledUp = pdImage.getWidth() < Math.round(at.getScaleX())
                || pdImage.getHeight() < Math.round(at.getScaleY());

        // if the image is scaled down, we use smooth interpolation, eg PDFBOX-2364
        // only when scaled up do we use nearest neighbour, eg PDFBOX-2302 / mori-cvpr01.pdf
        // stencils are excluded from this rule (see survey.pdf)
        if (isScaledUp || pdImage.isStencil()) {
            graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                    RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        }//from w  w w . j  a  v  a2 s  .co  m
    }

    if (pdImage.isStencil()) {
        // fill the image with paint
        BufferedImage image = pdImage.getStencilImage(getNonStrokingPaint());

        // draw the image
        drawBufferedImage(image, at);
    } else {
        // draw the image
        drawBufferedImage(pdImage.getImage(), at);
    }

    if (!pdImage.getInterpolate()) {
        // JDK 1.7 has a bug where rendering hints are reset by the above call to
        // the setRenderingHint method, so we re-set all hints, see PDFBOX-2302
        setRenderingHints();
    }
}

From source file:org.jcurl.demo.tactics.TrajectoryScenarioBean.java

private static Affine createSceneRock(final int i16, final int opacity) {
    SGNode rock = new SGRockFactory.Fancy().newInstance(i16);
    if (DoCacheRocks) {
        final SGRenderCache rc = new SGRenderCache();
        rc.setChild(rock);/*from  ww w  .jav a2s  . co  m*/
        rc.setInterpolationHint(RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        rock = rc;
    }
    return SGTransform.createAffine(new AffineTransform(), rock);
}

From source file:org.squidy.designer.shape.VisualShape.java

@Override
protected final void paint(PPaintContext paintContext) {
    super.paint(paintContext);

    Graphics2D g = paintContext.getGraphics();

    // Set default font.
    g.setFont(internalFont);/*ww w . ja  va 2s  . c  om*/

    //      if (!renderingHintsSet) {
    if (isRenderPrimitive()) {
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
        g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    } else {
        // Use anti aliasing -> May slow down performance.
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }
    //         renderingHintsSet = true;
    //      }

    // Paint the shapes visual representation.
    paintShape(paintContext);

    // Allows visual debugging if enabled.
    if (DebugConstants.ENABLED) {
        paintDebug(paintContext);
    }
}

From source file:sernet.verinice.service.commands.LoadAttachmentFile.java

private void drawThumbnail(BufferedImage image, BufferedImage resizedImage) {
    Graphics2D g = resizedImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    g.drawImage(image, 0, 0, resizedImage.getWidth(), resizedImage.getHeight(), null);
    g.dispose();/*from w  w  w . ja  v a  2  s .co  m*/
}