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) {
    BufferedImage bim;/*from w  ww .j a v  a 2s. c  o  m*/

    TexturePaint tp;

    String mesg = "www.java2s.com";

    Font myFont = new Font("Lucida Regular", Font.BOLD, 72);

    Color[] colors = { Color.red, Color.blue, Color.yellow, };

    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
    System.out.println(tp.getTransparency());

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setPaint(tp);
    g2d.setFont(myFont);
    g2d.drawString(mesg, 20, 100);
}

From source file:ala.soils2sat.DrawingUtils.java

public static void setPreferredAliasingMode(Graphics g) {
    if (g instanceof Graphics2D) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                (_AntiAliasedFonts ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF));
    }//from  w w w  . j  av  a 2  s.  c o m
}

From source file:TimerBasedAnimation.java

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

    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    g2.setRenderingHints(rh);//from   w  w  w. j a  va2s. c  o  m
    Dimension size = getSize();

    if (initialize) {
        reset(size.width, size.height);
        initialize = false;
    }
    this.step(size.width, size.height);
    render(size.width, size.height, g2);
}

From source file:Main.java

public void paint(Graphics g) {
    BufferedImage bim;//from w  w w.j  ava 2 s. c o  m

    TexturePaint tp;

    String mesg = "www.java2s.com";

    Font myFont = new Font("Lucida Regular", Font.BOLD, 72);

    Color[] colors = { Color.red, Color.blue, Color.yellow, };

    int width = 8, height = 8;
    bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = bim.createGraphics();
    for (int i = 0; i < width; i++) {
        g2.setPaint(colors[(i / 2) % colors.length]);
        g2.drawLine(0, i, i, 0);
        g2.drawLine(width - i, height, width, height - i);
    }
    Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight());
    tp = new TexturePaint(bim, r);
    tp.createContext(ColorModel.getRGBdefault(), new Rectangle(10, 10, 20, 20), null, null, null);

    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setPaint(tp);
    g2d.setFont(myFont);
    g2d.drawString(mesg, 20, 100);
}

From source file:com.github.lucapino.sheetmaker.PreviewJFrame.java

public static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) {
    int w = image.getWidth();
    int h = image.getHeight();
    BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = output.createGraphics();

    // This is what we want, but it only does hard-clipping, i.e. aliasing
    // g2.setClip(new RoundRectangle2D ...)
    // so instead fake soft-clipping by first drawing the desired clip shape
    // in fully opaque white with antialiasing enabled...
    g2.setComposite(AlphaComposite.Src);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);//from  w ww  .j  a v  a 2  s.  c o  m
    g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornerRadius, cornerRadius));

    // ... then compositing the image on top,
    // using the white shape from above as alpha source
    g2.setComposite(AlphaComposite.SrcIn);
    g2.drawImage(image, 0, 0, null);

    g2.dispose();

    return output;
}

From source file:bigdataproject.ScatterPlot.java

/**
 * Creates a new fast scatter plot.//  www.  jav a2 s.  c  o  m
 *
 * @param title the frame title.
 * @param samples the 2D matrix to plot.
 */
public ScatterPlot(final String title, double[][] samples, List<Cluster<DoublePoint>> list) {

    super(title);
    this.list = list;
    convertToFloat(samples);
    listToHashMap();
    HashMap<Integer, float[][]> clusterData = HashMapDoubleToFloat();
    final NumberAxis domainAxis = new NumberAxis("X1");
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis("X2");
    rangeAxis.setAutoRangeIncludesZero(false);
    final CustomFastScatterPlot plot = new CustomFastScatterPlot(this.data, domainAxis, rangeAxis, clusterData);
    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(1000, 540));
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(2000);
    setContentPane(panel);

}

From source file:facebean.FaceBean.java

@Override
public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Face/*from  w  w  w  .j av  a2  s.  c om*/
    int w = getWidth();
    int h = getHeight();
    int pad = 12;
    int cw = w - pad * 2;
    int ch = h - pad * 2;
    g2.setColor(getBackground());
    g2.fillArc(pad, pad, cw, ch, 0, 360);
    g2.setColor(getForeground());
    g2.drawArc(pad, pad, cw, ch, 0, 360);
    // Mouth
    int sw = cw / 2;
    int sh = ch / 2;
    if (mSmile == true)
        g2.drawArc(w / 2 - sw / 2, h / 2 - sh / 2, sw, sh, 270 - mMouthWidth / 2, mMouthWidth);
    else
        g2.drawArc(w / 2 - sw / 2, h / 2 + sh / 3, sw, sh, 90 - mMouthWidth / 2, mMouthWidth);
    // Eyes
    int er = 4;
    g2.fillArc(w / 2 - cw * 1 / 8 - er / 2, h / 2 - ch / 4 - er, er, er, 0, 360);
    g2.fillArc(w / 2 + cw * 1 / 8 - er / 2, h / 2 - ch / 4 - er, er, er, 0, 360);
}

From source file:scatterplot1k.JFreeScatter.java

/**
 * Creates a new fast scatter plot demo.
 *
 * @param title      the frame title./*from   ww  w  .j  a  va 2 s .  c o m*/
 * @param sampleSize
 */
public JFreeScatter(final String title, int sampleSize) {
    super(title);
    this.sampleCount = sampleSize;

    data = new float[2][sampleSize];
    populateData();
    final NumberAxis domainAxis = new NumberAxis("X");
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis("Y");
    rangeAxis.setAutoRangeIncludesZero(false);
    final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
    final JFreeChart chart = new JFreeChart("Fast Scatter Plot", 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(2000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(2000);

    setContentPane(panel);

}

From source file:se.dibbler.backend.generics.DibblerImageUtil.java

private static Response<BufferedImage> resizeWithHint(BufferedImage originalImage, int type, int height,
        int width) {
    try {/*from w w w .ja v a 2s .c om*/
        BufferedImage resizedImage = new BufferedImage(width, height, type);
        Graphics2D g = resizedImage.createGraphics();
        g.drawImage(originalImage, 0, 0, width, height, null);
        g.dispose();
        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 Response.success(resizedImage);
    } catch (Exception e) {
        LOG.error("[ ERROR when resizing file ] [ MESSAGE : {}]", e.getMessage());
        return Response.error(GenericError.FILE_HANDLING);
    }
}

From source file:IconPaint.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.white);/*from w  w w .  j  a  v a  2s  .c o  m*/
    Graphics2D g2 = (Graphics2D) g;

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

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

    g2.drawImage(img, 10, 10, 100, 100, this);
}