在我想要pick image from gallery
的项目中,用户可以触摸该图片pixel color store into my db.
问题:
它会给我例外:y must be <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)
代码:
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);
我正在尝试更多像set padding,设置Image layout动态但总是得到这个异常。
我在堆栈溢出和 Google 上进行了大量搜索,但未获得积极响应。
请给我一些想法。