开发者

while using g.drawImage(img,0,0,100,100,0,0,0,0,null) it does not produce any result?

开发者 https://www.devze.com 2022-12-21 11:21 出处:网络
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?As well as ensuring the image is loaded, the

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?


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号