Questions tagged [imageobserver]

ImageObserver is a Java interface for tracking the loading of images.

The ImageObserver provides:

An asynchronous update interface for receiving notifications about Image information as the Image is constructed.

The AWT class Toolkit provides many methods for loading and creating images, and most of them work asynchronously (the code continues on, while the image is loaded in the background).

Image loading can be tracked using a MediaTracker, but any class that implements an ImageObserver effectively takes over any steps necessary in updating the component or view as more of the image is loaded. The Swing based JComponent (parent of all other Swing components except top level containers) implements ImageObserver.

To leverage the power of the observer in custom painting, an image might be drawn to the Graphics instance using:

// Where 'this' implements ImageObserver
graphics.drawImage(img,0,0,this);
10 questions
19
votes
2 answers

What is an ImageObserver?

When you draw an image it requires an image observer. From what I understand so far a BufferedImage is an image observer. But my question is, what defines an image observer and what does it do? I'm quite confused.
Troubleshoot
  • 1,816
  • 1
  • 12
  • 19
2
votes
2 answers

Java can't instantiate an Image?

So for my 2D game I want to use an image to represent a player but when I try to use an image, it tells me that it couldn't be "instantiated". I don't know what that means: public class PlayerOne extends Entity{ private Image img = new…
Toreole
  • 33
  • 1
  • 10
1
vote
0 answers

Drawing a series of tile Images on a JPanel

EDITED (Updated code + question): I'm working on creating a 2D top-down RPG and I'm having many troubles painting small 32x32 images (256 total). I've had success painting many squares of grading colors though. So i can confirm that the nested…
0
votes
2 answers

Trying to add Image onto JFrame

Hello I'm trying to add an Image that I have on my desktop to my JFrame that I have created i have imported all the necessary functions and the correct variables the only trouble i have is with Image observer I set my x and y values for my image but…
0
votes
1 answer

What is the purpose of the ImageObserver field when getting the height and width of an image?

Java has this method: getWidth(ImageObserver observer) It returns the Width of an image. This method seems simple enough until you get to the part where an ImageObserver is requiered. What is the purpose of the ImageObserver as a parameter. Is…
Avi Caspe
  • 537
  • 4
  • 12
0
votes
1 answer

Java - Drawing Images Basically

I've come from Python to Java and am a bit confused. My main question is how to draw an image. I've looked on the oracle site but even when copy - pasting their code it didn't work. Here is what I had (excluding imports): public class…
Andy
  • 263
  • 1
  • 11
0
votes
1 answer

I am trying to replace a BufferedImage in my code with an animated gif

Currently in my code I have a BufferedImage drawn like: Graphics2D g2d = (Graphics2D) g; g2d.transform(at); //at is an AffineTransform that just rotates the .gif g2d.drawImage(sharkie, xCenter-5*radius, yCenter-3*radius, 10*radius, 6*radius,…
user3435133
  • 3
  • 1
  • 2
0
votes
1 answer

Java 2d Game: imageUpdate()

I am working on a Java 2d game, I want to make a method, to check id the images i will update are allready being rendered completely, if they are, then they are not going to be re-drawed. And now i am stuck. I searched for a way to do this and i…
Zaphyk
  • 157
  • 2
  • 8
0
votes
1 answer

getting the right image observer for rotating an image

So Im drawing a BufferedImage 'bird' but I want to rotate it according to the angle that it is falling. I have a bird object which contains the BufferedImage and a render() method which draw it rotated. public void render(Graphics2D g, ImageObserver…
Acor74u
  • 17
  • 5
0
votes
2 answers

Multiple animated images in a Icon?

I'm working on a simple game as a learning exercise. The game consists of a grid of squares, each of which has a background image and can contain any number of objects and player tokens layered on top of each other. At the moment, the board is just…
Leonide
  • 235
  • 3
  • 11