tags:

views:

47

answers:

3

while using g.drawImage(img,0,0,100,100,0,0,0,0,null) it does not produce any result. So how to draw on the image in file of a better way?

A: 

The last parameter in the drawImage method is an ImageObserver. Provide a valid implentation of ImageObserver, and check in the overridden imageUpdate method whether your image is getting updated or not.

From there on using proper debugging you can fing out why its not drawn

Suraj Chandran
A: 

Start out with just g.drawImage(img, x, y, observer); and see if you get anything. Note, the ImageObserver can be null.

Make sure that img has been loaded.

Also, make sure that the Graphics or Graphics2D object refers to something that you can see or verify the contents of. For instance, if it's a JPanel, make sure it's not hidden, etc. Or, if you're drawing to another image, try writing the image out to a file using ImageIO.write(img, "jpg", new File("test.jpg")) or something similar.

Tom
A: 

As well as ensuring the image is loaded, the last 4 int parameters are the source x,y,width,height... in specifying 0,0,0,0 you are asking the API to draw a 0x0 rectangle of the image starting at 0,0 - this should paint nothing. You probably wanting 0,0,100,100 for these, or use the overload that does not specify two sets of coordinates.

Software Monkey