图像的可见部分的Andr​​oid寄存器触摸事件? [英] Android register touch events on visible portion of image?

查看:161
本文介绍了图像的可见部分的Andr​​oid寄存器触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在思考如何我可以注册只是触及一个PNG图片中可以看到(不透明)的部分活动。

I've currently been thinking about how I could register only touch events on the visible (non-transparent) parts of a .PNG image.

-I've一直在测试与周围AndEngine,似乎他们有多种选择:我已经试过所有我能找到也没有用

-I've been testing around with AndEngine and it seems they have multiple options: I've tried any I could find to no avail.

- 我可以很可能创建自己的检查一个给定的触摸区域的透明度,我想的方法,但不知道有多少工作/这可能与屏幕上的物体15-20能够被感动创建开销..

-I could very possibly create my own method of checking a given touched area's transparency I suppose, but not sure how much work/overhead that might create with 15-20 objects on screen being able to be touched..

任何帮助很多AP preciated!

Any help is much appreciated!

推荐答案

一个简单的方法来做到这将是抢在触摸位置的像素颜色。然后,你可以检查像素是透明的:

One simple way to do it would be to grab the the pixel color at the touch location. Then you can check if the pixel is transparent:

int color = Bitmap.getPixel(x,y); // x and y are the location of the touch event in Bitmap space
int alpha = Color.getAlpha(color);
boolean isTransparent = (alpha==0);

注:根据您实现您的触摸监听器将可能需要到X转换,触摸事件的x的y位置,图像视图的y坐标

Note: Depending on how you implement your touch listener will might need to convert the x,y location of the touch event to the x,y coordinates of the image view.

这篇关于图像的可见部分的Andr​​oid寄存器触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆