【问题标题】:When touch an ImageView i need to display the touched area in another ImageView in android?触摸 ImageView 时,我需要在 android 的另一个 ImageView 中显示触摸区域吗?
【发布时间】:2015-07-14 11:16:47
【问题描述】:

我为此使用了这种方法:

croppedBitmap =Bitmap.createBitmap( sourceBitmap, x, y, 80, 80, mMatrix, true);

但在角落区域显示错误:

java.lang.IllegalArgumentException: x must be >= 0

附加图片显示我的预期结果

【问题讨论】:

  • 在裁剪之前,检查 x 和 y 参数,如果 >=0,则结束 - 裁剪较小的图像,然后绘制它。

标签: android image-processing


【解决方案1】:
   ImageView imageView = (ImageView) findViewById(R.id.iv_imageview);
   imageView.setOnTouchListener(new OnTouchListener(){

   @Override
   public boolean onTouch(View v, MotionEvent event) {
    int topParam =  imageView.getPaddingTop();
    int rightParam =  imageView.getPaddingRight();
    int maxTopParam = topParam+imageView.getMaxHeight();
    int maxRightParam = rightParam + imageView.getMaxWidth();
     if(event.getX>topParam&&event.getX<maxTopParam){
        //the x coordinate is in your image... do the same to Y
     }
      });
    return true;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多