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:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

public void draw(Graphics2D g2, ChartPanel chartPanel, XYPlot plot, Color fillColor,
        Collection<? extends VisualPeakAnnotation> shapes,
        Collection<? extends VisualPeakAnnotation> selectedShapes) {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Shape savedClip = g2.getClip();
    Rectangle2D dataArea = chartPanel.getScreenDataArea();
    g2.clip(dataArea);/*from   w w  w .  j  a va2 s  .  co  m*/

    ValueAxis xAxis = plot.getDomainAxis();
    RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
    ValueAxis yAxis = plot.getRangeAxis();
    RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
    Color c = g2.getColor();
    //         Color fillColor = peakAnnotations.getColor();
    //         if (fillColor == null || fillColor.equals(Color.WHITE) || fillColor.equals(new Color(255, 255, 255, 0))) {
    ////            System.out.println("Peak annotation color was null or white, using color from treatment group!");
    //            fillColor = peakAnnotations.getChromatogram().getTreatmentGroup().getColor();
    //         }
    for (VisualPeakAnnotation x : shapes) {
        Shape s = toViewXY(x, chartPanel, x.getCenter());
        switch (x.getPeakAnnotationType()) {
        case LINE:
            drawEntity(s, g2, fillColor, null, chartPanel, false, 0.1f);
            break;
        case OUTLINE:
            //                  plot.addAnnotation(new XYShapeAnnotation(x, new BasicStroke(1.0f), new Color(fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue(), 64), new Color(254, 254, 254, 254)), false);
            drawOutline(s, g2, fillColor, Color.DARK_GRAY, chartPanel, false, 0.25f);
            break;
        case POINTER:
            drawEntity(s, g2, fillColor, Color.DARK_GRAY, chartPanel, false, 0.25f);
            break;
        default:
            drawEntity(s, g2, fillColor, null, chartPanel, false, 0.1f);
        }
    }
    for (VisualPeakAnnotation x : selectedShapes) {
        Shape s = toViewXY(x, chartPanel, x.getCenter());
        switch (x.getPeakAnnotationType()) {
        case LINE:
            drawEntity(s, g2, fillColor, Color.BLACK, chartPanel, false, 1f);
            break;
        case OUTLINE:
            //                  plot.addAnnotation(new XYShapeAnnotation(x, new BasicStroke(1.0f), new Color(fillColor.getRed(),fillColor.getGreen(),fillColor.getBlue(),64), new Color(254,254,254,254)), false);
            drawOutline(s, g2, fillColor, Color.BLACK, chartPanel, false, 1f);
            break;
        case POINTER:
            drawEntity(s, g2, fillColor, Color.BLACK, chartPanel, false, 1f);
            break;
        default:
            drawEntity(s, g2, fillColor, Color.BLACK, chartPanel, false, 1f);
        }
    }
    g2.setColor(c);
    g2.setClip(savedClip);
    //         chartPanel.repaint();
}

From source file:net.sf.maltcms.common.charts.api.XYChartBuilder.java

/**
 *
 */// w w w. j av  a2  s.c  o  m
public XYChartBuilder() {
    plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
    chart = new JFreeChart(plot);
    renderingHints = new RenderingHints(null);
    renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
    renderingHints.put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100);
    renderingHints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    renderingHints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    renderingHints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
    renderingHints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    renderingHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    renderingHints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    renderingHints.put(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
}

From source file:TexturedText.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setPaint(tp);//ww w .  j ava 2 s  . c  om
    g2.setFont(myFont);
    g2.drawString(mesg, 20, 100);
}

From source file:org.kuali.mobility.people.service.PeopleServiceImpl.java

@Override
public BufferedImage generateObfuscatedImage(String text) {
    int width = 250;
    int height = 25;

    BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    Graphics2D g2d = bufferedImage.createGraphics();
    Font font = new Font("Arial", Font.PLAIN, 14);
    g2d.setFont(font);//from   w ww.  j  a  v a2 s  .c  o m

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    g2d.setRenderingHints(rh);

    Paint bg = new Color(255, 255, 255);
    g2d.setPaint(bg);
    g2d.fillRect(0, 0, width, height);

    int x = 0;
    int y = height - 7;

    Paint textPaint = new Color(0, 0, 0);
    g2d.setPaint(textPaint);
    g2d.drawString(text, x, y);

    g2d.dispose();
    return bufferedImage;
}

From source file:z.tool.util.image.ImageUtil.java

/**
 * ??(???)/*from  w ww. j a va  2 s  . c om*/
 */
public static void mergeResource(int bufferedImageType, InputStream inputStream, ImageType destType,
        OutputStream outputStream, int newHeight, int newWidth, Mergeable mergeable, Mergeable... mergeables) {
    if (null == inputStream) {
        throw new IllegalArgumentException("inputStream is null");
    }

    if (null == destType) {
        throw new IllegalArgumentException("destType is null");
    }

    if (null == outputStream) {
        throw new IllegalArgumentException("outputStream is null");
    }

    try {
        Image srcImage = ImageIO.read(inputStream);

        // ?
        int srcImageWidth = srcImage.getWidth(null);
        int srcImageHeight = srcImage.getHeight(null);

        // ????
        if (0 == newWidth || 0 == newHeight) {
            newWidth = srcImageWidth;
            newHeight = srcImageHeight;
        }

        BufferedImage distImage = new BufferedImage(newWidth, newHeight, bufferedImageType);

        // 
        Graphics2D graphics2d = distImage.createGraphics();
        graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        graphics2d.drawImage(srcImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null);

        // ??(?)
        mergeable.draw(graphics2d);

        // ??(?)
        if (null != mergeables && mergeables.length > 0) {
            for (Mergeable d : mergeables) {
                d.draw(graphics2d);
            }
        }

        // ?
        ImageIO.write(distImage, destType.name(), outputStream);
    } catch (IOException e) {
        LOG.error("method:mergeResource,destType:" + destType + ",newHeight:" + newHeight + ",newWidth:"
                + newWidth + ",errorMsg:" + e.getMessage(), e);
        throw new HumanNeededError(Error.IO_ERROR);
    }
}

From source file:eu.planets_project.tb.impl.data.util.ImageThumbnail.java

/**
 * Create a scaled jpeg of an image. The width/height ratio is preserved.
 * //w w  w . j  a  v  a  2s  .co  m
 * <p>
 * If image is smaller than thumbWidth x thumbHeight, it will be magnified,
 * otherwise it will be scaled down.
 * </p>
 * 
 * @param image
 *            the image to reduce
 * @param thumbWidth
 *            the maximum width of the thumbnail
 * @param thumbHeight
 *            the maximum heigth of the thumbnail
 * @param quality
 *            the jpeg quality ot the thumbnail
 * @param out
 *            a stream where the thumbnail data is written to
 */
public static void createThumb(Image image, int thumbWidth, int thumbHeight, OutputStream out)
        throws Exception {
    int imageWidth = image.getWidth(null);
    int imageHeight = image.getHeight(null);
    double thumbRatio = (double) thumbWidth / (double) thumbHeight;
    double imageRatio = (double) imageWidth / (double) imageHeight;
    if (thumbRatio < imageRatio) {
        thumbHeight = (int) (thumbWidth / imageRatio);
    } else {
        thumbWidth = (int) (thumbHeight * imageRatio);
    }
    // draw original image to thumbnail image object and
    // scale it to the new size on-the-fly
    BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = thumbImage.createGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    graphics2D.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
    // save thumbnail image to out stream
    log.debug("Start writing rescaled image...");
    ImageIO.write(thumbImage, "png", out);
    log.debug("DONE writing rescaled image...");
}

From source file:edu.kit.dama.ui.components.TextImage.java

/**
 * Get the bytes of the final image.//from   w w w . ja v  a2  s  . com
 *
 * @return The byte array containing the bytes of the resulting image.
 *
 * @throws IOException if creating the image fails.
 */
public byte[] getBytes() throws IOException {
    Image transparentImage = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(
            new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB).getSource(), new RGBImageFilter() {
                @Override
                public final int filterRGB(int x, int y, int rgb) {
                    return (rgb << 8) & 0xFF000000;
                }
            }));

    //create the actual image and overlay it by the transparent background
    BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = outputImage.createGraphics();
    g2d.drawImage(transparentImage, 0, 0, null);
    //draw the remaining stuff
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2d.setColor(color);
    g2d.fillRoundRect(0, 0, size, size, 20, 20);
    g2d.setColor(new Color(Math.round((float) color.getRed() * .9f), Math.round((float) color.getGreen() * .9f),
            Math.round((float) color.getBlue() * .9f)));
    g2d.drawRoundRect(0, 0, size - 1, size - 1, 20, 20);

    Font font = new Font("Dialog", Font.BOLD, size - 4);
    g2d.setFont(font);
    g2d.setColor(Color.WHITE);

    String s = text.toUpperCase().substring(0, 1);
    FontMetrics fm = g2d.getFontMetrics();
    float x = ((float) size - (float) fm.stringWidth(s)) / 2f;
    float y = ((float) fm.getAscent()
            + (float) ((float) size - ((float) fm.getAscent() + (float) fm.getDescent())) / 2f) - 1f;
    g2d.drawString(s, x, y);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ImageIO.write(outputImage, "png", bout);
    g2d.dispose();
    return bout.toByteArray();
}

From source file:org.evors.rs.ui.sandpit.TrialViewer.java

@Override
public void draw() {
    if (buffer == null) {
        return;//  www  . j  a  v a2s.  c  om
    }
    Graphics2D g2 = (Graphics2D) buffer.getDrawGraphics();
    camera.setWindowSize(new Vector2D(this.getWidth(), this.getHeight()));
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, getWidth(), getHeight());
    AffineTransform prevTrans = g2.getTransform();
    g2.setTransform(camera.getTransform());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    grid.draw(g2);
    if (world != null) {
        SandpitRenderer.drawWorld(g2, world);
    }
    if (path != null) {
        path.draw(g2);
    }
    if (robot != null) {
        SandpitRenderer.drawRobot(g2, robot);
    }
    g2.setTransform(prevTrans);
    drawText(g2,
            String.format("Time: %.2f\nRobot position: {%.2f,%.2f}\nRobot heading: %.2f\nInputs:%s\nNeurons:%s",
                    time, robot.getPosition().getX(), robot.getPosition().getY(), robot.getHeading(),
                    Arrays.toString(robot.getInput()),
                    Arrays.toString(((CTRNN) controller.getController()).getNeurons())));
}

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

/**
 * This will draw the page to the requested context.
 *
 * @param g The graphics context to draw onto.
 * @param p The page to draw./*from  w  w w . j av  a2  s  .  c  om*/
 * @param pageDimension The size of the page to draw.
 *
 * @throws IOException If there is an IO error while drawing the page.
 */
public void drawPage(Graphics g, PDPage p, Dimension pageDimension) throws IOException {
    graphics = (Graphics2D) g;
    page = p;
    pageSize = pageDimension;
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    // Only if there is some content, we have to process it. 
    // Otherwise we are done here and we will produce an empty page
    if (page.getContents() != null) {
        PDResources resources = page.findResources();
        processStream(page, resources, page.getContents().getStream());
    }
    List annotations = page.getAnnotations();
    for (int i = 0; i < annotations.size(); i++) {
        PDAnnotation annot = (PDAnnotation) annotations.get(i);
        PDRectangle rect = annot.getRectangle();
        String appearanceName = annot.getAppearanceStream();
        PDAppearanceDictionary appearDictionary = annot.getAppearance();
        if (appearDictionary != null) {
            if (appearanceName == null) {
                appearanceName = "default";
            }
            Map appearanceMap = appearDictionary.getNormalAppearance();
            if (appearanceMap != null) {
                PDAppearanceStream appearance = (PDAppearanceStream) appearanceMap.get(appearanceName);
                if (appearance != null) {
                    g.translate((int) rect.getLowerLeftX(), (int) -rect.getLowerLeftY());
                    processSubStream(page, appearance.getResources(), appearance.getStream());
                    g.translate((int) -rect.getLowerLeftX(), (int) +rect.getLowerLeftY());
                }
            }
        }
    }

}

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

protected void paintComponent(Graphics g) {

    // prepare graphic object
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // set clipping area
    if (is_printing) {
        g2d.translate(-draw_area.x, -draw_area.y);
        g2d.setClip(draw_area);/*w w w  .ja v  a 2 s.c  o m*/
    }

    //paint canvas background
    if (!is_printing) {
        g2d.setColor(getBackground());
        g2d.fillRect(0, 0, getWidth(), getHeight());
    }

    // paint white background on drawing area    
    g2d.setColor(Color.white);
    g2d.fillRect(draw_area.x, draw_area.y, draw_area.width, draw_area.height);
    if (!is_printing) {
        g2d.setColor(Color.black);
        g2d.draw(draw_area);
    }

    // paint
    paintChart(g2d);

    // dispose graphic object
    g2d.dispose();

    revalidate();
}