Example usage for java.awt AlphaComposite SRC_OVER

List of usage examples for java.awt AlphaComposite SRC_OVER

Introduction

In this page you can find the example usage for java.awt AlphaComposite SRC_OVER.

Prototype

int SRC_OVER

To view the source code for java.awt AlphaComposite SRC_OVER.

Click Source Link

Document

The source is composited over the destination (Porter-Duff Source Over Destination rule).

Usage

From source file:Main.java

public static void main(String[] args) throws IOException {
    URL url = new URL("http://www.java2s.com/style/download.png");
    BufferedImage im = ImageIO.read(url);
    URL url2 = new URL("http://www.java2s.com/style/download.png");
    BufferedImage im2 = ImageIO.read(url2);
    Graphics2D g = im.createGraphics();
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
    g.drawImage(im2, (im.getWidth() - im2.getWidth()) / 2, (im.getHeight() - im2.getHeight()) / 2, null);
    g.dispose();/*from ww  w. j av a2 s .  c  o m*/

    display(im);
    ImageIO.write(im, "jpeg", new File("output.jpeg"));
}

From source file:Main.java

/**
 * Changes the opacity of a given image.
 * @param src The source image./*from  w  w  w .j  ava 2 s  .c o  m*/
 * @param opacity The opacity to change to.
 * @return
 */
public static BufferedImage imgUtilAdjustImageTransparency(BufferedImage src, float opacity) {
    if (src == null)
        return null;
    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
    BufferedImage cpy = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = (Graphics2D) cpy.getGraphics();
    g.setComposite(ac);
    g.drawImage(src, 0, 0, null);
    g.dispose();
    return cpy;
}

From source file:TransparentRectangles.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;
    for (int i = 1; i <= 10; i++) {
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, i * 0.1f));
        g2d.fillRect(50 * i, 20, 50, 50);
    }/*w ww .  j  av a  2  s. c o m*/
}

From source file:net.sf.mzmine.modules.visualization.tic.PeakTICPlotRenderer.java

private static Composite makeComposite(final float alpha) {

    return AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
}

From source file:Transparency.java

public static BufferedImage makeImageTranslucent(BufferedImage source, double alpha) {
    BufferedImage target = new BufferedImage(source.getWidth(), source.getHeight(),
            java.awt.Transparency.TRANSLUCENT);
    // Get the images graphics
    Graphics2D g = target.createGraphics();
    // Set the Graphics composite to Alpha
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha));
    // Draw the image into the prepared reciver image
    g.drawImage(source, null, 0, 0);//from  w w  w  . jav a 2  s  .  com
    // let go of all system resources in this Graphics
    g.dispose();
    // Return the image
    return target;
}

From source file:FadeOutImage.java

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

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
    g2d.drawImage(myImage, 10, 10, null);
}

From source file:MainClass.java

public void paint(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);/*from w w w  .  j  ava2 s.  com*/

    int x = 40, y = 40;

    g.setColor(Color.red);
    g.fillOval(x, y, 50, 50);

    Composite old = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));

    g.setColor(Color.green);
    g.fillOval(x + 30, y + 30, 30, 30);

    g2.setComposite(old);

    g.setColor(Color.black);
    g.drawString("AlphaComposite.SRC_OVER", x, y + 80);

}

From source file:TransparentText.java

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

    // the rendering quality.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // a red rectangle.
    Rectangle2D r = new Rectangle2D.Double(50, 50, 550, 100);
    g2.setPaint(Color.red);/*from   w ww.j a v a  2  s .  c  o m*/
    g2.fill(r);
    // a composite with transparency.
    Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f);
    g2.setComposite(c);
    // Draw some blue text.
    g2.setPaint(Color.blue);
    g2.setFont(new Font("Times New Roman", Font.PLAIN, 72));
    g2.drawString("Java Source and Support", 25, 130);
}

From source file:ColorFadingAnimation.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(new Color(50, 50, 50));
    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);//w w  w. j av a  2 s .c  o m
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha_rectangle));
    g2d.fill(rect);
}

From source file:MainClass.java

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

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

    Rectangle2D r = new Rectangle2D.Double(50, 50, 150, 100);
    g2.setPaint(Color.red);/*from  w  ww . ja v  a2  s . c  o  m*/
    g2.fill(r);

    Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f);
    g2.setComposite(c);

    g2.setPaint(Color.blue);
    g2.setFont(new Font("Times New Roman", Font.PLAIN, 72));
    g2.drawString("www.java2s.com", 25, 130);
}