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

Discussion in 'Java' started by Wolfgang, Feb 10, 2004.

  1. Wolfgang

    Wolfgang Guest

    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
    Wolfgang, Feb 10, 2004
    #1
    1. Advertising

  2. Re: Is graphics2d.drawImage(image, 0, 0, w, h, null) an asynchronousoperation?

    Wolfgang wrote:

    > 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?

    --

    Knute Johnson
    email s/nospam/knute/
    Molon labe...
    Knute Johnson, Feb 10, 2004
    #2
    1. Advertising

  3. Wolfgang

    Wolfgang Guest

    Knute Johnson <> wrote in message news:<8aceb36416cf3b38433f89c09b565357@news.1usenet.com>...
    > Wolfgang wrote:
    >
    > > The question: is this use
    > > of drawImage a asynchronous operation?
    > >

    >
    > 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
    Wolfgang, Feb 10, 2004
    #3
  4. Re: Is graphics2d.drawImage(image, 0, 0, w, h, null) an asynchronousoperation?

    Wolfgang wrote:
    > Knute Johnson <> wrote in message news:<8aceb36416cf3b38433f89c09b565357@news.1usenet.com>...
    >
    >>Wolfgang wrote:
    >>
    >>
    >>>The question: is this use
    >>>of drawImage a asynchronous operation?
    >>>

    >>
    >>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


    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.

    --

    Knute Johnson
    email s/nospam/knute/
    Molon labe...
    Knute Johnson, Feb 10, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Amadeus
    Replies:
    0
    Views:
    492
    Amadeus
    Sep 2, 2003
  2. Michele Puccini
    Replies:
    0
    Views:
    394
    Michele Puccini
    Nov 9, 2003
  3. OtisUsenet
    Replies:
    3
    Views:
    12,506
    OtisUsenet
    Feb 24, 2004
  4. Replies:
    1
    Views:
    479
    Boudewijn Dijkstra
    May 1, 2005
  5. Replies:
    8
    Views:
    3,092
    Andrew Thompson
    Nov 16, 2006
Loading...

Share This Page