I have not tried this, it just occurred to me when I read your question. What about this one.
Say ImageView does not have a gasket, and gravity is set to the center. The problem is that you cannot just use Drawable width and height to calculate the position of the rectangle, as it can be resized to fit the ImageView. Therefore, you should use ImageView sizes and the ratio of ImageView and Drawable.
When the ratio of Drawable and ImageView is equal, then Drawable completely fills the ImageView, and then the rectangle corresponds to the size of the ImageView. Rectangle coordinates (from the upper left corner, counter): (0/0), (ImageView width / 0), (ImageView width, ImageView height), (0 / ImageView height),
When the coefficients do not match and, for example, you can say that Drawable is wider than ImageView, then Drawable will fill the full width of the ImageView, but not fill the height. But as the Drawable is centered, we can calculate the y coordinate of the upper left corner of the Drawables and therefore for the rectangle. First, calculate the current Drawable height in the ImageView. This must be done because Drawable doesn’t have their original sizes, as they were resized to fit the ImageView.
current height Drawable = (Drawable height / Drawable width) * ImageView width
y value of the coordinate of the upper left corner:
y = (ImageView height - Drawable current height) / 2
Thus, the coordinates of the rectangle (from the upper left corner, counter): (0 / y), (ImageView / y width), (ImageView / y width + height Drawable height), (0 / y + current height Raised)
I hope you get this idea. If Drawable is higher than ImageView, then you can calculate it in the same way, but you must exchange width and height values.