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:org.eqaula.glue.faces.MethodPrinter.java

public Method printToDownload(Method method) {

    try {/*w w w  . ja  v  a 2 s . co m*/

        if (Method.Type.SEMAPHORE.equals(method.getMethodType())) {

            // So, browser is requesting the image. Get ID value from actual request param.
            BufferedImage bufferedImg = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2 = bufferedImg.createGraphics();
            String color = "gray"; //Default color
            if (!method.getWrappers().isEmpty()) {
                color = method.getWrappers().get(0).getValue();
            }
            Field field = Class.forName("java.awt.Color").getField(color);
            g2.setColor((Color) field.get(null));
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            Ellipse2D.Float sign1 = new Ellipse2D.Float(0F, 0F, 32F, 32F);
            g2.fill(sign1);
            //g2.drawString(method.getTarget().getCurrentValue().toString(), 0, 10);
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            ImageIO.write(bufferedImg, "png", os);

            writeStreamedContentToFile(method, new ByteArrayInputStream(os.toByteArray()));

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return method;
}

From source file:Starry.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.white);//from   w w  w .  j  av a  2 s.c  o m
    w = getSize().width;
    h = getSize().height;
    Graphics2D g2;
    g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    FontRenderContext frc = g2.getFontRenderContext();
    Font f = new Font("Helvetica", 1, w / 10);
    String s = new String("The Starry Night");
    TextLayout textTl = new TextLayout(s, f, frc);
    AffineTransform transform = new AffineTransform();
    Shape outline = textTl.getOutline(null);
    Rectangle r = outline.getBounds();
    transform = g2.getTransform();
    transform.translate(w / 2 - (r.width / 2), h / 2 + (r.height / 2));
    g2.transform(transform);
    g2.setColor(Color.blue);
    g2.draw(outline);
    g2.setClip(outline);
    g2.drawImage(img, r.x, r.y, r.width, r.height, this);

}

From source file:lk.ac.mrt.projectx.buildex.complex.FormalVerifier.java

/**
 * Creates a new fast scatter plot demo.
 *
 * @param title the frame title.// w w  w.  ja  va 2s.  c  o  m
 */
public FormalVerifier(final String title, final String lblx, final String lbly) throws IOException {

    super(title);
    populateData();
    final NumberAxis domainAxis = new NumberAxis(lblx);
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis(lbly);
    rangeAxis.setAutoRangeIncludesZero(false);
    final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
    final JFreeChart chart = new JFreeChart(title, plot);
    //        chart.setLegend(null);

    // force aliasing of the rendered content..
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setPreferredSize(new java.awt.Dimension(800, 600));
    //      panel.setHorizontalZoom(true);
    //    panel.setVerticalZoom(true);
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(3000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(3000);

    setContentPane(panel);
    //TODO : Print

    ChartUtilities.saveChartAsJPEG(
            new File("F:\\FYP2\\FinalP\\graphs\\Twirl" + System.currentTimeMillis() + ".jpg"), chart, 800, 600);

}

From source file:game.com.HandleUploadGameThumbServlet.java

public static BufferedImage resizeImage(final Image image, int width, int height) {
    final BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    final Graphics2D graphics2D = bufferedImage.createGraphics();
    graphics2D.setComposite(AlphaComposite.Src);
    //below three lines are for RenderingHints for better image quality at cost of higher processing time
    graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.drawImage(image, 0, 0, width, height, null);
    graphics2D.dispose();//from w ww.j av  a2 s  .c  om
    return bufferedImage;
}

From source file:org.springframework.cloud.stream.app.pose.estimation.processor.PoseEstimateOutputMessageBuilder.java

private byte[] drawPoses(byte[] imageBytes, List<Body> bodies) throws IOException {

    if (bodies != null) {

        BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(imageBytes));

        Graphics2D g = originalImage.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Stroke stroke = g.getStroke();
        g.setStroke(new BasicStroke(this.poseProperties.getDrawLineWidth()));

        for (Body body : bodies) {
            for (Limb limb : body.getLimbs()) {

                Color limbColor = findLimbColor(body, limb);

                Part from = limb.getFromPart();
                Part to = limb.getToPart();

                if (limb.getLimbType() != Model.LimbType.limb17
                        && limb.getLimbType() != Model.LimbType.limb18) {
                    g.setColor(limbColor);
                    g.draw(new Line2D.Double(from.getNormalizedX(), from.getNormalizedY(), to.getNormalizedX(),
                            to.getNormalizedY()));
                }/*from w  w w  .  j  a  va  2  s.c  om*/

                g.setStroke(new BasicStroke(1));
                drawPartOval(from, this.poseProperties.getDrawPartRadius(), g);
                drawPartOval(to, this.poseProperties.getDrawPartRadius(), g);
                g.setStroke(new BasicStroke(this.poseProperties.getDrawLineWidth()));
            }
        }

        g.setStroke(stroke);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(originalImage, IMAGE_FORMAT, baos);
        baos.flush();
        imageBytes = baos.toByteArray();
        baos.close();
        g.dispose();
    }

    return imageBytes;
}

From source file:edu.ku.brc.ui.GradiantButton.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int w = this.getWidth();
    int h = this.getHeight();

    drawButtonBody(g2, w, h, getForeground());

    if (pressed) {
        g2.translate(1, 1);// w  w w  .  j  a  v a 2s.c o  m
    }

    String text = getText();
    if (isNotEmpty(text)) {
        drawText(g2, w, h, getText());
    }

    Icon roIcon = getRolloverIcon();
    Icon paintedIcon = isHover && roIcon != null ? roIcon : icon;
    if (paintedIcon != null) {
        //Graphics2D g2 = (Graphics2D) g.create();
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, iconAlpha));
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        paintedIcon.paintIcon(this, g2, (w - icon.getIconWidth()) / 2, (h - icon.getIconHeight()) / 2);
    }
}

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 v a  2s  .com*/

    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

/**
 *
 *//*  ww  w. j  ava2s . 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);//from w ww  .  jav  a 2s .  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);// w ww  . j  a v  a2s  . 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;
}