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:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

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

    String s = "www.java2s.com www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);/*from ww w  .  j  ava2 s. co m*/

    GlyphVector gv = font.createGlyphVector(frc, s);
    System.out.println(gv.getVisualBounds());

    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

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

    String s = "www.java2s.com www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 24);
    FontRenderContext frc = g2.getFontRenderContext();
    g2.translate(40, 80);//  w  w  w  .  j  av a2 s  . c  o m

    GlyphVector gv = font.createGlyphVector(frc, s);
    System.out.println(gv.getLogicalBounds());

    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        double theta = (double) i / (double) (length - 1) * Math.PI / 4;
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(theta);
        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2.fill(transformedGlyph);
    }
}

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    String s = "www.java2s.com";
    Dimension d = getSize();/*from www .  ja va 2 s .c  om*/

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font serifFont = new Font("Serif", Font.PLAIN, 48);
    Font sansSerifFont = new Font("Monospaced", Font.PLAIN, 48);

    AttributedString as = new AttributedString(s);
    as.addAttribute(TextAttribute.FONT, serifFont);
    as.addAttribute(TextAttribute.FONT, sansSerifFont, 2, 5);
    as.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 5);

    g2.drawString(as.getIterator(), 40, 80);

}

From source file:Main.java

private static BufferedImage resizeImageWithHint(BufferedImage originalImage, int type) {
    int IMG_WIDTH = 512;
    int IMG_CLAHEIGHT = 512;
    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_CLAHEIGHT, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_CLAHEIGHT, null);
    g.dispose();/*from w  w  w. j a  v  a2s . com*/
    g.setComposite(AlphaComposite.Src);

    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    return resizedImage;
}

From source file:LineDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);//w  ww.  j  a va 2s . c  om
    int x = 5;
    int y = 7;

    g2.draw(new Line2D.Double(x, y, 200, 200));
    g2.drawString("Line2D", x, 250);

}

From source file:FilledArc.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int x = 5;/*from   ww  w .  j a va  2  s  . c  o m*/
    int y = 7;

    // fill Arc2D
    g2.setPaint(Color.red);
    g2.fill(new Arc2D.Double(x, y, 200, 200, 90, 135, Arc2D.OPEN));
    g2.setPaint(Color.black);
    g2.drawString("Filled Arc2D", x, 250);

}

From source file:SwingTimerBasedAnimationScaleRotate.java

public void paint(Graphics g) {
    int h = getHeight();
    int w = getWidth();

    Graphics2D g2d = (Graphics2D) g;

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

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

    g2d.translate(w / 2, h / 2);//from  w ww .j a  v a2 s  .  c  om
    g2d.rotate(angle);
    g2d.scale(scale, scale);

    g2d.fill(r);
}

From source file:GradientPaintEllipse.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int x = 5;//from  ww  w .  j a  v  a2s .c o m
    int y = 7;

    // fill Ellipse2D.Double
    GradientPaint redtowhite = new GradientPaint(x, y, Color.red, 200, y, Color.white);
    g2.setPaint(redtowhite);
    g2.fill(new Ellipse2D.Double(x, y, 200, 200));
    g2.setPaint(Color.black);
    g2.drawString("Filled Ellipse2D", x, 250);
}

From source file:FilledRectangleDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);/*from   w  ww .  jav  a  2 s. c o  m*/
    int x = 5;
    int y = 7;

    g2.setPaint(Color.red);
    g2.fill(new Rectangle2D.Double(x, y, 200, 200));
    g2.setPaint(Color.black);
    g2.drawString("Filled Rectangle2D", x, 250);
}

From source file:GradientPaintDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);/*from w  w  w. j  a  v a 2s  .c  om*/
    int x = 5;
    int y = 7;
    // fill RoundRectangle2D.Double
    GradientPaint redtowhite = new GradientPaint(x, y, Color.red, 200, y, Color.blue);
    g2.setPaint(redtowhite);
    g2.fill(new RoundRectangle2D.Double(x, y, 200, 200, 10, 10));
    g2.setPaint(Color.black);
    g2.drawString("Filled RoundRectangle2D", x, 250);

}