Get the displayed size of an image inside an ImageView

后端 未结 4 852
时光取名叫无心
时光取名叫无心 2020-12-01 04:47

The code is simple:



        
4条回答
  •  再見小時候
    2020-12-01 05:33

    Here is a helper function to get the bounds of image in an imageView.

    /**
     * Helper method to get the bounds of image inside the imageView.
     *
     * @param imageView the imageView.
     * @return bounding rectangle of the image.
     */
    public static RectF getImageBounds(ImageView imageView) {
        RectF bounds = new RectF();
        Drawable drawable = imageView.getDrawable();
        if (drawable != null) {
            imageView.getImageMatrix().mapRect(bounds, new RectF(drawable.getBounds()));
        }
        return bounds;
    }
    

提交回复
热议问题