Example usage for java.awt RenderingHints VALUE_ANTIALIAS_ON

List of usage examples for java.awt RenderingHints VALUE_ANTIALIAS_ON

Introduction

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

Prototype

Object VALUE_ANTIALIAS_ON

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

Click Source Link

Document

Antialiasing hint value -- rendering is done with antialiasing.

Usage

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

/**
 * Draw a frame around the image; color depends on resolution if wanted
 *
 * @param movie/*ww  w.  j av a2s. co m*/
 * @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.j a  v  a 2  s. c om
    // 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:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java

private Queue<BufferedImage> createBody() {

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

    //// ww w  .  j a va 2s .  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 w  ww  . j a  va  2s .  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//w ww.  j  a  v a2s. 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   w  w  w.  ja v  a  2 s. com
        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);/* ww  w  .  j av  a2 s  . c  o  m*/

    /*
     * 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);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

private static Paint createTransparentCheckeredPaint(Color color, int checkerSize) {
    int s = checkerSize;
    BufferedImage bufferedImage = new BufferedImage(2 * s, 2 * s, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = bufferedImage.createGraphics();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
            RenderingHints.VALUE_ANTIALIAS_ON);

    Color c1 = DataStructureUtils.setColorAlpha(color, (int) (color.getAlpha() * .8));
    Color c2 = DataStructureUtils.setColorAlpha(color, (int) (color.getAlpha() * .2));
    g2.setStroke(new BasicStroke(0));
    g2.setPaint(c2);/* w w w  .  jav a 2  s  .c  om*/
    g2.setColor(c2);
    g2.fillRect(0, 0, s, s);
    g2.fillRect(s, s, s, s);
    g2.setPaint(c1);
    g2.setColor(c1);
    g2.fillRect(0, s, s, s);
    g2.fillRect(s, 0, s, s);

    // paint with the texturing brush
    Rectangle2D rect = new Rectangle2D.Double(0, 0, 2 * s, 2 * s);
    return new TexturePaint(bufferedImage, rect);
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void drawBusyBox(Graphics2D g2, JXLayer<? extends V> layer) {
    final Font oldFont = g2.getFont();
    final Font font = oldFont;
    final FontMetrics fontMetrics = g2.getFontMetrics(font);

    // Not sure why. Draw GIF image on JXLayer, will cause endless setDirty
    // being triggered by system.
    //final Image image = ((ImageIcon)Icons.BUSY).getImage();
    //final int imgWidth = Icons.BUSY.getIconWidth();
    //final int imgHeight = Icons.BUSY.getIconHeight();
    //final int imgMessageWidthMargin = 5;
    final int imgWidth = 0;
    final int imgHeight = 0;
    final int imgMessageWidthMargin = 0;

    final String message = MessagesBundle.getString("info_message_retrieving_latest_stock_price");
    final int maxWidth = imgWidth + imgMessageWidthMargin + fontMetrics.stringWidth(message);
    final int maxHeight = Math.max(imgHeight, fontMetrics.getHeight());

    final int padding = 5;
    final int width = maxWidth + (padding << 1);
    final int height = maxHeight + (padding << 1);
    final int x = (int) this.drawArea.getX() + (((int) this.drawArea.getWidth() - width) >> 1);
    final int y = (int) this.drawArea.getY() + (((int) this.drawArea.getHeight() - height) >> 1);

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Composite oldComposite = g2.getComposite();
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(COLOR_BORDER);//from   w ww  .j  ava 2  s.co m
    g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15);
    g2.setColor(COLOR_BACKGROUND);
    g2.setComposite(Utils.makeComposite(0.75f));
    g2.fillRoundRect(x, y, width, height, 15, 15);
    g2.setComposite(oldComposite);
    g2.setColor(oldColor);

    //g2.drawImage(image, x + padding, y + ((height - imgHeight) >> 1), layer.getView());

    g2.setFont(font);
    g2.setColor(COLOR_BLUE);

    int yy = y + ((height - fontMetrics.getHeight()) >> 1) + fontMetrics.getAscent();
    g2.setFont(font);
    g2.setColor(COLOR_BLUE);
    g2.drawString(message, x + padding + imgWidth + imgMessageWidthMargin, yy);
    g2.setColor(oldColor);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    g2.setFont(oldFont);
}