Is graphics2d.drawImage(image, 0, 0, w, h, null) an asynchronous operation?

W

Wolfgang

Assume I have an image 'img'.
Rreading the image from a file, I made sure I really have the entire
image available by using a MediaTracker.

Now I want to print the image into a BufferedImage using drawImage on
the graphics object of the BufferedImage. The question: is this use
of drawImage a asynchronous operation?

So here is what I want to do:

bufImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2d. = bufImage.createGraphics();
// get and image named 'img' here;
// getting the image is asynchronous
// so use a MediaTracker to make sure it has arrived.

// Now that I am sure I have the complete image 'img', I draw it
graphics2d.drawImage(img, 0, 0, w, h, null);
System.out.println("Question: Am I guranteed at this point to have");

System.out.println(" 'img' completely in the buffered image?");
System.out.println(" Or did drawImage go off on a thread while I");
System.out.println(" continue parallel execution?");

If graphics2d.drawImage(image, 0, 0, w, h, null) is asynchronous, is
there a way to wait for it to complete (like a MediaTracker for
loading an image from disk)?

Thanks,

Wolfgang
Santa Barbara, CA
 
K

Knute Johnson

Wolfgang said:
Assume I have an image 'img'.
Rreading the image from a file, I made sure I really have the entire
image available by using a MediaTracker.

Now I want to print the image into a BufferedImage using drawImage on
the graphics object of the BufferedImage. The question: is this use
of drawImage a asynchronous operation?

So here is what I want to do:

bufImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2d. = bufImage.createGraphics();
// get and image named 'img' here;
// getting the image is asynchronous
// so use a MediaTracker to make sure it has arrived.

// Now that I am sure I have the complete image 'img', I draw it
graphics2d.drawImage(img, 0, 0, w, h, null);
System.out.println("Question: Am I guranteed at this point to have");

System.out.println(" 'img' completely in the buffered image?");
System.out.println(" Or did drawImage go off on a thread while I");
System.out.println(" continue parallel execution?");

If graphics2d.drawImage(image, 0, 0, w, h, null) is asynchronous, is
there a way to wait for it to complete (like a MediaTracker for
loading an image from disk)?

Thanks,

Wolfgang
Santa Barbara, CA

Yes.

That being said, why don't you use ImageIO.read() to get a BufferedImage
in the first place?
 
W

Wolfgang

Knute Johnson said:
Yes.

That being said, why don't you use ImageIO.read() to get a BufferedImage
in the first place?

I wanted to know because I use
graphics2d.drawImage(img, ...);
to make intermediate copies of a buffered image objects (for temporary
safe keeping) and my GUI may depend on one of those intermediate
copies. I copy like this

graphics2dOfBufferedImage_temp.drawImage(bufferedImageToCopy, ...);

Perhaps you know a better way of making copies of a buffered Image.
If so, please tell me.

Thanks,
Wolfgang
 
K

Knute Johnson

Wolfgang said:
I wanted to know because I use
graphics2d.drawImage(img, ...);
to make intermediate copies of a buffered image objects (for temporary
safe keeping) and my GUI may depend on one of those intermediate
copies. I copy like this

graphics2dOfBufferedImage_temp.drawImage(bufferedImageToCopy, ...);

Perhaps you know a better way of making copies of a buffered Image.
If so, please tell me.

Thanks,
Wolfgang

Wolfgang:

I don't know what the performance costs of doing that are. It is
probably as efficient as any other method of copying. You could try
experimenting with BufferedImage.getRGB() and comparing the two methods
for temporary storage.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top