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

/**
 * Fills a gradient using the start color and end color specified.
 *
 * @param g/*from   w  w w  .ja  v  a2 s  . c o  m*/
 *          the gradient
 * @param s
 *          the shape to fill
 * @param start
 *          the start color
 * @param end
 *          the end color
 * @param vertical
 *          true for a vertical gradient; false for horizontal
 */
public static void fillGradient(Graphics2D g, Shape s, Color start, Color end, boolean vertical) {
    Rectangle r = s.getBounds();
    Paint gp = new GradientPaint(0, 0, start, vertical ? 0 : r.width, vertical ? r.height : 0, end);
    Object o = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setPaint(gp);
    g.fill(s);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, o);
}

From source file:MainClass.java

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

    String s = "www.java2s.com";
    Dimension d = getSize();//from w  ww  . j  av  a  2s .  c o  m

    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();// www  .ja  v  a 2  s.c  o m
    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);//from  ww w . j av  a  2s  . c  o m
    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;//  w w w .  j  a  v  a 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 ww w.  ja  va  2  s  .c o m*/
    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;//w w w .jav a  2s .  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);/* w w w  . java2 s. c om*/
    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  2 s .  c  o m*/
    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);

}

From source file:MouseMoveScale.java

public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2d = (Graphics2D) g;

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

    g2d.setColor(new Color(0, 0, 200));
    g2d.fill(myRect);/*from   w w w.ja  v  a 2  s  .  c o  m*/
}