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}

[2308 byte] By [JavaChipa] at [2007-9-28 11:09:57]
# 1
try this22 dcHolder.draw(new Ellipse2D.Float(0, 0, 2, 10));
sethmussa at 2007-7-12 1:32:06 > top of Java-index,Other Topics,Java Game Development...
# 2
rather22 dcHolder.draw(new Ellipse2D.Float((float)0, (float)0, (float)2, (float)10));
sethmussa at 2007-7-12 1:32:06 > top of Java-index,Other Topics,Java Game Development...
# 3
This does not work. Also, I am not using swing. I really think this has nothing to do with the method for drawing the elipse. Something is wrong with drawing to the image
JavaChipa at 2007-7-12 1:32:06 > top of Java-index,Other Topics,Java Game Development...
# 4
The problem does not have to do with the method that draws the oval. Anyway, I need someone to help me out here, as I am under a lot of pressure to fix this problem.
JavaChipa at 2007-7-12 1:32:06 > top of Java-index,Other Topics,Java Game Development...
# 5
I dont see any usage of MediaTracker or ImageObserver, how are you ensuring your images are fully loaded before you try and use them?
Abusea at 2007-7-12 1:32:06 > top of Java-index,Other Topics,Java Game Development...
# 6

That is not the issue here. Please read my original post. The images are being displayed but the oval is not being drawn at line 24 I believe. I am using source code with MediaTracker, but I did not want to post a thousand lines of code.

I think I need help from someone who has much experience with BufferedImage and device context on those images.

JavaChipa at 2007-7-12 1:32:06 > top of Java-index,Other Topics,Java Game Development...
# 7

Can you post some working code? I can't make your code compile. The code you posted makes it look like DisplayCanvas is a local class within the Constructor of TBufferedImage2, but it looks like something is missing; it's not clear where the local class closing brace should be and then it's not even referred to later. So please repost with some working code if you want more help.

I agree with Abuse though, I wouldn't be surprised if the GIF images aren't loaded and so when you attempt to draw them on a Graphics context, nothing gets drawn. Depending on your situation, you might want to use a MediaTracker to wait for the images to load, or use a ImageObserver to handle it asynchronously. The MediaTracker would be simpler though and better in most cases. Yeah, the Image class in Java is way screwy. Argh. God bless BufferedImages though. =)

cdbennetta at 2007-7-12 1:32:06 > top of Java-index,Other Topics,Java Game Development...
# 8
I have always used the Media Tracker class!, and the images are loading.I will post the code in a while, as I am pretty busy. Thanks.
JavaChipa at 2007-7-12 1:32:06 > top of Java-index,Other Topics,Java Game Development...