Writing and combining BufferedImage(s)
I am trying to draw an oval on an Image (Contains a gif). After the oval is drawn,I want to place the new modified image on top of another image and then display the combined images to the screen. Note that the oval Must be drawn before lines 24 and 26 are executed. Here is the code. The combined image is displayed at line 33, but the oval is never drawn onto MyButtonImage. I can not figure out what the problem is here. Note that if I draw the oval at line 27, it works (functionally) but I need to do this before lines 24-26 are executed.
1 public class TBufferedImage2 extends javax.swing.JFrame {
2public TBufferedImage2() {
3class DisplayCanvas extends JPanel {
4int x, y; // Location of image.
5private AlphaComposite alpha;
6BufferedImage bi_BackGround;
7BufferedImage bi_MyButtonImage;
8Image FirstImage = getToolkit().getImage("BackDrop.gif");
9Image MyButtonImage = getToolkit().getImage("buttons.gif");
10bi_BackGround = new BufferedImage(FirstImage.getWidth s), //// Back Ground Image that the
11FirstImage.getHeight(this),// button will be placed on
12 BufferedImage.TYPE_INT_ARGB);
13 bi_MyButtonImage = new BufferedImage(FirstImage.getWidth(this), // Foreground Image
14 FirstImage.getHeight(this), // Gif of a button
15 BufferedImage.TYPE_INT_ARGB);
16 Graphics2D dcButton = bi_MyButtonImage.createGraphics();
17 Graphics2D dcBackGround = bi_BackGround.createGraphics();
18 Graphics2D dcHolder = bi_MyButtonImage.createGraphics();
19
20 dcHolder.drawImage(MyButtonImage , 0,0, null);
21 dcButton.setComposite(AlphaComposite.SrcOver);
22 dcHolder.drawOval(2,2,10,10); // Draw an Oval on MyButtonImage (won't work)
// Note that this will not work either->
// dcButton.drawOval(2,2,10,10);
23
24 dcButton.drawImage(FirstImage, 0,0, null);
25 // Next place the Modified MyButtomImage on top of the first image.
26dcButton.drawImage(MyButtonImage , 0,0, null);
27
28 }
29
30 public void paintComponent(Graphics g) {
31 super.paintComponent(g);
32 Graphics2D g2D = (Graphics2D) g;
33g2D.drawImage(bi_MyButtonImage, x, y, this); // display final image
34}

