AlphaComposite.SRC_ATOP : AlphaComposite « java.awt « Java by API






AlphaComposite.SRC_ATOP

 


import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JPanel {
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f);

    BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gbi = buffImg.createGraphics();

    gbi.setPaint(Color.red);
    gbi.fillRect(0, 0, 40, 40);
    gbi.setComposite(ac);

    gbi.setPaint(Color.green);
    gbi.fillRect(5, 5, 40, 40);

    g2d.drawImage(buffImg, 20, 20, null);
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame("Composition");
    frame.add(new CompositingDST_ATOP());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 120);
    frame.setVisible(true);
  }
}

   
  








Related examples in the same category

1.AlphaComposite.CLEAR
2.AlphaComposite.DST_ATOP
3.AlphaComposite.DST_IN
4.AlphaComposite.DST_OUT
5.AlphaComposite.DST_OVER
6.AlphaComposite.SRC
7.AlphaComposite.SRC_IN
8.AlphaComposite.SRC_OVER
9.AlphaComposite.SRC_OUT
10.AlphaComposite: getInstance(int rule, float alpha)