有没有办法获取在Android上绘制位图的矩形?
我正在尝试子类化 ImageView
并在 Bitmap
上绘制一些内容。但是我找不到一种方法来获取绘制 Bitmap
的 Rect
。我只能通过ImageView
的getDrawingRect(Rect)
方法获取其中ImageView
绘制的Rect
。下面是我想要得到的内容的说明:
我想要的矩形是蓝色的。提前致谢。
I am trying to subclass ImageView
and draw something on Bitmap
. However I cannot find a way to get the Rect
in which Bitmap
is drawn. I can only get the Rect
in which ImageView
is drawn by getDrawingRect(Rect)
method of ImageView
. Below is an illustration of what I want to get:
The Rect I want is the blue one. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定的图像将根据给定的属性(例如高度、宽度、缩放因子等)在 ImageView 中绘制。
因此 getDrawingRect() 方法给出 ImageView 的整个区域。如果更改 ImageView 内的可绘制对象,蓝色区域可能会根据图像属性和 imageview 属性而发生变化。但黄色区域不会改变,因为它是固定的并且仅基于 ImageView,与显示的图像无关。
我认为没有机会绘制位图的矩形。不要认为我的回答是100%正确的,这只是一个建议。
您可以从绘图缓存获取有关蓝色区域的信息。尝试一次。
我希望它可以帮助你。
The given image will be drawn in the ImageView based on the attributes given e.g., height, width, scaling factors, etc.
So that the getDrawingRect() method giving the entire area of ImageView. If you change the drawable inside ImageView the blue colored area may change based on the image properties and imageview properties. But the yellow colored area won't change because it is fixed and based on the ImageView only, its independent of image displayed.
I think no chance to get the Rect of bitmap drawn. Don't think my answer is 100% correct, it is just a suggestion only.
You may get information about blue colored area from Drawing Cache. Try it once.
I hope it may help you.