How can I get height and width of an image?

前端 未结 5 1045
野的像风
野的像风 2021-01-04 19:40

Why is the following bit of code returns Height: -1 which means that the height is yet not known. How to get height of the image?

 try {
        // Create a          


        
5条回答
  •  时光取名叫无心
    2021-01-04 20:07

    Because the image is loaded asynchronously, in the background.

    As the getHeight() javadoc says, you need to provide an ImageObserver (instead of null), which is called when the image has been loaded.

提交回复
热议问题