如何让Android的ImageView的像素 [英] How to get Imageview pixel in android

查看:570
本文介绍了如何让Android的ImageView的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目,我想接从画廊图片然后用户可触摸的图像和像素的彩色存储到我的分贝。

In my project i want to pick image from gallery then user can touch that image and that pixel color store into my db.

问题:

这会给我的异常: y必须是< bitmap.height()

logcat的:

07-22 16:38:59.406: E/AndroidRuntime(6139): java.lang.IllegalArgumentException: y must be < bitmap.height()
07-22 16:38:59.406: E/AndroidRuntime(6139):     at android.graphics.Bitmap.checkPixelAccess(Bitmap.java:788)
07-22 16:38:59.406: E/AndroidRuntime(6139):     at android.graphics.Bitmap.getPixel(Bitmap.java:740)
07-22 16:38:59.406: E/AndroidRuntime(6139):     at com.example.mycolorreader.PhotoActivity$2.onTouch(PhotoActivity.java:121)
07-22 16:38:59.406: E/AndroidRuntime(6139):     at android.view.View.dispatchTouchEvent(View.java:3762)
07-22 16:38:59.406: E/AndroidRuntime(6139):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-22 16:38:59.406: E/AndroidRuntime(6139):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-22 16:38:59.406: E/AndroidRuntime(6139):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-22 16:38:59.406: E/AndroidRuntime(6139):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
07-22 16:38:59.406: E/AndroidRuntime(6139):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)

code:

final Bitmap bitmap = ((BitmapDrawable) ivPhoto.getDrawable()).getBitmap();
ivPhoto.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        int pixel = bitmap.getPixel(x, y);

我尝试像集填充更多的东西,设置图像布局动态的,但总能得到这个例外。

I am try many more thing like set padding,set Image layout dynamic but always get this exception.

我搜索很多关于堆栈溢出谷歌,但没有得到正面回应。

I am search lot on Stack overflow and Google but not getting positive response.

请给我一些想法。

推荐答案

事件的x / y是触摸坐标。为了获得感动位图的像素,首先要隐蔽他们为位图的坐标。这个过程是非常好的描述这里

Event's x/y is touch coordinates. To get touched bitmap's pixel, we should first covert them to bitmap coordinates. This procedure was very nice described here.

这篇关于如何让Android的ImageView的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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