Android 位图 OnTouch 问题
我在画布上根据 .png 文件绘制了 5 个位图 - 一个头、一个身体以及两条胳膊和腿。
如何检测 OnTouch 上触摸了其中哪一个?更具体地说,我可以检测 OnTouch 是否在所触摸的身体部位的实际形状内吗?
我的意思是,显然,.png 本身是矩形的,但是 Android 是否知道,或者我可以告诉它,忽略图像内的透明度吗?
I've drawn 5 bitmaps from .png files on a canvas - a head, a body and two arms and legs.
How can I detect which of these has been touched on an OnTouch? And, more specifically, can I detect if the OnTouch was within the actual shape of the body part touched?
What I mean is, obviously, the .pngs themselves are rectangular, but does Android know, or can I tell it, to ignore the transparency within the image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以获取所触摸的像素的颜色,并将其与这些坐标处背景上的像素的颜色进行比较。
编辑:好的,忽略这一点,您无法获取画布上像素的颜色,因此,获取触摸的 x,y,检查是否有任何身体部位图像被触摸,如果是,则取触摸 x,y 得到图像的 x,y,然后获取图像的像素,该像素应该是透明的或彩色的。
You could get the colour of pixel touched and compare it to the colour of pixel on the background at those co-ords.
EDIT: ok, ignore that, you can't get the colour of a pixel on the canvas, so instead, get the x,y of the touch, check if any of the body part images have been touched, if so, take the x,y of the image from the touch x,y, then get the pixel of the image, which should be transparent or colour.