Example usage for java.awt RenderingHints KEY_ANTIALIASING

List of usage examples for java.awt RenderingHints KEY_ANTIALIASING

Introduction

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

Prototype

Key KEY_ANTIALIASING

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

Click Source Link

Document

Antialiasing hint key.

Usage

From source file:org.pentaho.di.core.gui.SwingDirectGC.java

public void setAntialias(boolean antiAlias) {
    if (antiAlias) {

        RenderingHints hints = new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
        hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
        // hints.add(new RenderingHints(RenderingHints.KEY_ALPHA_INTERPOLATION,
        // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY));
        gc.setRenderingHints(hints);//  w  ww. j a  v  a2s  . c o  m
    }
}

From source file:com.moviejukebox.plugin.DefaultImagePlugin.java

/**
 * Draw a frame around the image; color depends on resolution if wanted
 *
 * @param movie/*from  w w  w  .java2s . c om*/
 * @param bi
 * @return
 */
private BufferedImage drawFrame(Movie movie, BufferedImage bi) {
    BufferedImage newImg = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D newGraphics = newImg.createGraphics();
    newGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int cornerRadius2 = 0;

    if (!movie.isHD()) {
        String[] colorSD = frameColorSD.split("/");
        int[] lengthSD = new int[colorSD.length];
        for (int i = 0; i < colorSD.length; i++) {
            lengthSD[i] = Integer.parseInt(colorSD[i]);
        }
        newGraphics.setPaint(new Color(lengthSD[0], lengthSD[1], lengthSD[2]));
    } else if (highdefDiff) {
        if (movie.isHD()) {
            // Otherwise use the 720p
            String[] color720 = frameColor720.split("/");
            int[] length720 = new int[color720.length];
            for (int i = 0; i < color720.length; i++) {
                length720[i] = Integer.parseInt(color720[i]);
            }
            newGraphics.setPaint(new Color(length720[0], length720[1], length720[2]));
        }

        if (movie.isHD1080()) {
            String[] color1080 = frameColor1080.split("/");
            int[] length1080 = new int[color1080.length];
            for (int i = 0; i < color1080.length; i++) {
                length1080[i] = Integer.parseInt(color1080[i]);
            }
            newGraphics.setPaint(new Color(length1080[0], length1080[1], length1080[2]));
        }
    } else {
        // We don't care, so use the default HD logo.
        String[] colorHD = frameColorHD.split("/");
        int[] lengthHD = new int[colorHD.length];
        for (int i = 0; i < colorHD.length; i++) {
            lengthHD[i] = Integer.parseInt(colorHD[i]);
        }
        newGraphics.setPaint(new Color(lengthHD[0], lengthHD[1], lengthHD[2]));
    }

    if (roundCorners) {
        cornerRadius2 = cornerRadius;
    }

    RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, bi.getWidth(), bi.getHeight(),
            rcqFactor * cornerRadius2, rcqFactor * cornerRadius2);
    newGraphics.setClip(rect);

    // image fitted into border
    newGraphics.drawImage(bi, (int) (rcqFactor * frameSize - 1), (int) (rcqFactor * frameSize - 1),
            (int) (bi.getWidth() - (rcqFactor * frameSize * 2) + 2),
            (int) (bi.getHeight() - (rcqFactor * frameSize * 2) + 2), null);

    BasicStroke s4 = new BasicStroke(rcqFactor * frameSize * 2);

    newGraphics.setStroke(s4);
    newGraphics.draw(rect);
    newGraphics.dispose();

    return newImg;
}

From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java

private Queue<BufferedImage> createFooter() {

    // creating a backbuffer image on which we should draw the bkgColor for this colormap element
    final BufferedImage image = ImageUtils.createImage(1, 1, (IndexColorModel) null, transparent);
    final Map<Key, Object> hintsMap = new HashMap<Key, Object>();
    final Graphics2D graphics = ImageUtils.prepareTransparency(transparent, backgroundColor, image, hintsMap);

    // list where we store the rows for the footer
    final Queue<BufferedImage> queue = new LinkedList<BufferedImage>();
    // //the height is already fixed
    // final int rowHeight=(int)Math.round(rowH);
    final int rowWidth = (int) Math.round(footerW);
    // final Rectangle clipboxA=new Rectangle(0,0,rowWidth,rowHeight);
    ////w w w  . ja va 2s.  c o m
    // footer
    //
    //
    // draw the various bodyCells
    for (Cell cell : footerRows) {

        // get dim
        final Dimension dim = cell.getPreferredDimension(graphics);
        // final int rowWidth=(int)Math.round(dim.getWidth());
        final int rowHeight = (int) Math.round(dim.getHeight());
        final Rectangle clipboxA = new Rectangle(0, 0, rowWidth, rowHeight);

        // draw it
        final BufferedImage colorCellLegend = new BufferedImage(rowWidth, rowHeight,
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D rlg = colorCellLegend.createGraphics();
        rlg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        cell.draw(rlg, clipboxA, border);
        rlg.dispose();

        queue.add(colorCellLegend);

    }

    graphics.dispose();

    return queue;// mergeRows(queue);
}

From source file:MyJava3D.java

public Graphics2D createGraphics2D(int width, int height, BufferedImage bi, Graphics g) {

    Graphics2D g2 = null;/*from  w  w  w .  j a  v a 2 s .  c  om*/

    if (bi != null) {
        g2 = bi.createGraphics();
    } else {
        g2 = (Graphics2D) g;
    }

    g2.setBackground(getBackground());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, AntiAlias);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, Rendering);

    if (clearSurface || clearOnce) {
        g2.clearRect(0, 0, width, height);
        clearOnce = false;
    }

    if (texture != null) {
        // set composite to opaque for texture fills
        g2.setComposite(AlphaComposite.SrcOver);
        g2.setPaint(texture);
        g2.fillRect(0, 0, width, height);
    }

    if (composite != null) {
        g2.setComposite(composite);
    }

    return g2;
}

From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java

private Queue<BufferedImage> createBody() {

    final Queue<BufferedImage> queue = new LinkedList<BufferedImage>();

    ///*from   w  w  w . ja  v a 2  s .  c o  m*/
    // draw the various elements
    //
    // create the boxes for drawing later
    final int rowHeight = (int) Math.round(rowH);
    final int colorWidth = (int) Math.round(colorW);
    final int ruleWidth = (int) Math.round(ruleW);
    final int labelWidth = (int) Math.round(labelW);
    final Rectangle clipboxA = new Rectangle(0, 0, colorWidth, rowHeight);
    final Rectangle clipboxB = new Rectangle(0, 0, ruleWidth, rowHeight);
    final Rectangle clipboxC = new Rectangle(0, 0, labelWidth, rowHeight);

    //
    // Body
    //
    //
    // draw the various bodyCells
    for (ColorMapEntryLegendBuilder row : bodyRows) {

        //
        // row number i
        //
        // get element for color default behavior
        final Cell colorCell = row.getColorManager();
        // draw it
        final BufferedImage colorCellLegend = new BufferedImage(colorWidth, rowHeight,
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D rlg = colorCellLegend.createGraphics();
        rlg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        colorCell.draw(rlg, clipboxA, border);
        rlg.dispose();

        BufferedImage ruleCellLegend = null;
        if (forceRule) {
            // get element for rule
            final Cell ruleCell = row.getRuleManager();
            // draw it
            ruleCellLegend = new BufferedImage(ruleWidth, rowHeight, BufferedImage.TYPE_INT_ARGB);
            rlg = ruleCellLegend.createGraphics();
            rlg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            ruleCell.draw(rlg, clipboxB, borderRule);
            rlg.dispose();
        }

        // draw it if it is present
        if (labelWidth > 0) {
            // get element for label
            final Cell labelCell = row.getLabelManager();
            if (labelCell != null) {
                final BufferedImage labelCellLegend = new BufferedImage(labelWidth, rowHeight,
                        BufferedImage.TYPE_INT_ARGB);
                rlg = labelCellLegend.createGraphics();
                rlg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                rlg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                        RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
                labelCell.draw(rlg, clipboxC, borderLabel);
                rlg.dispose();

                //
                // merge the bodyCells for this row
                //
                //

                final Map<Key, Object> hintsMap = new HashMap<Key, Object>();
                queue.add(LegendUtils.hMergeBufferedImages(colorCellLegend, ruleCellLegend, labelCellLegend,
                        hintsMap, transparent, backgroundColor, dx));
            } else {
                final Map<Key, Object> hintsMap = new HashMap<Key, Object>();
                queue.add(LegendUtils.hMergeBufferedImages(colorCellLegend, ruleCellLegend, null, hintsMap,
                        transparent, backgroundColor, dx));
            }

        } else {
            //
            // merge the bodyCells for this row
            //
            //

            final Map<Key, Object> hintsMap = new HashMap<Key, Object>();
            queue.add(LegendUtils.hMergeBufferedImages(colorCellLegend, ruleCellLegend, null, hintsMap,
                    transparent, backgroundColor, dx));

        }

    }

    // return the list of legends
    return queue;// mergeRows(queue);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java

public BufferedImage getImage() {
    // Create an image that supports transparent pixels
    Dimension d = getPreferredSize();
    BufferedImage img = GraphicUtils.createCompatibleImage(d.width, d.height, false);

    // prepare graphics context
    Graphics2D g2d = img.createGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    g2d.setBackground(new Color(255, 255, 255, 0));

    // paint/*from  www.  j av  a  2 s  . c o  m*/
    is_printing = true;
    this.paint(g2d);
    is_printing = false;

    return img;
}

From source file:com.moviejukebox.plugin.DefaultImagePlugin.java

/**
 * Draw rounded corners on the image/*  ww  w .j ava 2s . c o m*/
 *
 * @param bi
 * @return
 */
protected BufferedImage drawRoundCorners(BufferedImage bi) {
    BufferedImage newImg = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D newGraphics = newImg.createGraphics();
    newGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, bi.getWidth(), bi.getHeight(),
            rcqFactor * cornerRadius, rcqFactor * cornerRadius);
    newGraphics.setClip(rect);
    newGraphics.drawImage(bi, 0, 0, null);

    newGraphics.dispose();
    return newImg;
}

From source file:org.openstreetmap.josm.tools.ImageProvider.java

public static BufferedImage createImageFromSvg(SVGDiagram svg, Dimension dim) {
    float realWidth = svg.getWidth();
    float realHeight = svg.getHeight();
    int width = Math.round(realWidth);
    int height = Math.round(realHeight);
    Double scaleX = null, scaleY = null;
    if (dim.width != -1) {
        width = dim.width;/*from  www.  j  a va  2 s  .c om*/
        scaleX = (double) width / realWidth;
        if (dim.height == -1) {
            scaleY = scaleX;
            height = (int) Math.round(realHeight * scaleY);
        } else {
            height = dim.height;
            scaleY = (double) height / realHeight;
        }
    } else if (dim.height != -1) {
        height = dim.height;
        scaleX = scaleY = (double) height / realHeight;
        width = (int) Math.round(realWidth * scaleX);
    }
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = img.createGraphics();
    g.setClip(0, 0, width, height);
    if (scaleX != null) {
        g.scale(scaleX, scaleY);
    }
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    try {
        svg.render(g);
    } catch (SVGException ex) {
        return null;
    }
    return img;
}

From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java

private BufferedImage mergeRows(Queue<BufferedImage> legendsQueue) {
    // I am doing a straight cast since I know that I built this
    // dimension object by using the widths and heights of the various
    // bufferedimages for the various bkgColor map entries.
    final Dimension finalDimension = new Dimension();
    final int numRows = legendsQueue.size();
    finalDimension.setSize(Math.max(footerW, colorW + ruleW + labelW) + 2 * dx + 2 * margin,
            rowH * numRows + 2 * margin + (numRows - 1) * dy);

    final int totalWidth = (int) finalDimension.getWidth();
    final int totalHeight = (int) finalDimension.getHeight();
    BufferedImage finalLegend = ImageUtils.createImage(totalWidth, totalHeight, (IndexColorModel) null,
            transparent);//from w  ww  .  j a  va  2  s.  c om

    /*
     * For RAMP type, only HORIZONTAL or VERTICAL condition is valid
     */
    if (colorMapType == ColorMapType.RAMP) {

        final Map<Key, Object> hintsMap = new HashMap<Key, Object>();
        Graphics2D finalGraphics = ImageUtils.prepareTransparency(transparent, backgroundColor, finalLegend,
                hintsMap);
        hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        finalGraphics.setRenderingHints(hintsMap);

        int topOfRow = (int) (margin + 0.5);
        for (int i = 0; i < numRows; i++) {
            final BufferedImage img = legendsQueue.remove();

            // draw the image
            finalGraphics.drawImage(img, (int) (margin + 0.5), topOfRow, null);
            topOfRow += img.getHeight() + dy;

        }

        if (this.layout == LegendLayout.HORIZONTAL) {
            BufferedImage newImage = new BufferedImage(totalHeight, totalWidth, finalLegend.getType());
            Graphics2D g2 = newImage.createGraphics();
            g2.rotate(-Math.PI / 2, 0, 0);
            g2.drawImage(finalLegend, null, -totalWidth, 0);
            finalLegend = newImage;
            g2.dispose();
            finalGraphics.dispose();
        }
    } else {
        List<RenderedImage> imgs = new ArrayList<RenderedImage>(legendsQueue);

        LegendMerger.MergeOptions options = new LegendMerger.MergeOptions(imgs, (int) dx, (int) dy,
                (int) margin, 0, backgroundColor, transparent, true, layout, rowWidth, rows, columnHeight,
                columns, null, false, false);
        finalLegend = LegendMerger.mergeRasterLegends(options);
    }

    return finalLegend;

}

From source file:org.csstudio.swt.widgets.figures.ImageFigure.java

private void initRenderingHints() {
    transcoder.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    transcoder.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    transcoder.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    transcoder.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    transcoder.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
}