Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to Edit a cropped photo in Android
    text
    copied!<p>I'm building an Android app where I have to edit a picture which has been picked from the phone gallery and cropped. </p> <p>So in my layout, I have an ImageView where I am placing the cropped image </p> <p>xml file </p> <pre><code>&lt;ImageView android:id="@+id/ivEditPhoto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:layout_weight=".90" android:src="@drawable/app_icon_big" /&gt; </code></pre> <p>Placing the cropped image in ImaveView</p> <pre><code>bitmapPic = (Bitmap) getIntent().getParcelableExtra( "CroppedBitmapImage"); picView = (ImageView) findViewById(R.id.ivEditPhoto); picView.setImageBitmap(bitmapPic); </code></pre> <p>The image is getting placed correctly. But the problem is when I try to edit it. I have an edit button and on click of that I do the following which includes registering of On Touch Listener. </p> <pre><code>DisplayMetrics displaymetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int height = displaymetrics.heightPixels; int width = displaymetrics.widthPixels; Bitmap alteredPastedBitmap = Bitmap.createBitmap(bitmapPic.getWidth(), bitmapPic.getHeight(), bitmapPic.getConfig()); pasteCanvas = new Canvas(alteredPastedBitmap); paint = new Paint(); paint.setColor(Color.GREEN); paint.setStrokeWidth(5); matrix = new Matrix(); pasteCanvas.drawBitmap(bitmapPic, matrix, paint); picView.setOnTouchListener(this); </code></pre> <p>Then the following </p> <pre><code>public boolean onTouch(View v, MotionEvent event) { Toast.makeText(this, v.getId(), Toast.LENGTH_SHORT).show(); if (v.getId() == R.id.ivEditPhoto) { Toast.makeText(this, "onTouch", Toast.LENGTH_SHORT).show(); int action = event.getAction(); x = event.getX(); y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: sX = event.getX(); sY = event.getY(); break; case MotionEvent.ACTION_UP: if (skewedBitmap == null) { int resID = 0; if (imageId == 0) resID = R.drawable.green_arrow; else resID = imageId; bitmapToPaste = BitmapFactory.decodeResource( getResources(), resID); } else { bitmapToPaste = skewedBitmap; skewedBitmap = null; } pasteCanvas.drawBitmap(bitmapToPaste, sX- (bitmapToPaste.getWidth() / 2),sY- (bitmapToPaste.getHeight() / 2), null); picView.invalidate(); break; case MotionEvent.ACTION_CANCEL: break; default: break; } } return true; } </code></pre> <p>The issue is: the bitmapPic.getWidth() and bitmapPic.getHeight() is 160*160 and the onTouch event.getX(); and event.getY(); is beyond the co-ordinates (For example: 150.33 &amp; 500.89) although the image seems to be occupying the whole screen and the touch is on the image. So onTouch doesn't place the bitmap and returns a false. Could any of you please guide me on this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload