Note that there are some explanatory texts on larger screens.

plurals
  1. PORestrict Bitmap should not cross out particular region from imageview
    primarykey
    data
    text
    <p>I have set bitmap in imageview and doing operation rotating and dragging bitmap on touch mutiple times. I want bitmap set in imageview should not go outside from particular region in imageview. </p> <p>Is there any way to achieve this.</p> <p>Please help me for this..</p> <pre><code>@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.save(); scaleCount=scaleCount+scale; angleCount = addAngle(angleCount, Math.toDegrees(angle)); if (!isInitialized) { int w = getWidth(); int h = getHeight(); position.set(w / 2, h / 2); isInitialized = true; } Paint paint = new Paint(); paint.setFilterBitmap(true); //Log.v("Height and Width", "Height: "+ getHeight() + "Width: "+ getWidth()); transform.reset(); transform.postTranslate(-width / 2.0f, -height / 2.0f); transform.postRotate((float) Math.toDegrees(angle)); transform.postScale(scale, scale); transform.postTranslate(position.getX(), position.getY()); rectangleF = new RectF(); transform.mapRect(rectangleF); //Log.v("VM", "Rect " + rectangleF.left + " " + rectangleF.top + " " + rectangleF.right + " " + rectangleF.bottom); canvas.drawBitmap(bitmap, transform, paint); canvas.restore(); BitmapWidth=BitmapWidth+bitmap.getScaledWidth(canvas); BitmapHeight=BitmapHeight+bitmap.getScaledHeight(canvas); } @Override public boolean onTouch(View v, MotionEvent event) { vca = null; vcb = null; vpa = null; vpb = null; x = event.getX(); y = event.getY(); try { touchManager.update(event); if (touchManager.getPressCount() == 1) { vca = touchManager.getPoint(0); vpa = touchManager.getPreviousPoint(0); position.add(touchManager.moveDelta(0)); } else { if (touchManager.getPressCount() == 2) { vca = touchManager.getPoint(0); vpa = touchManager.getPreviousPoint(0); vcb = touchManager.getPoint(1); vpb = touchManager.getPreviousPoint(1); VMVector2D current = touchManager.getVector(0, 1); VMVector2D previous = touchManager.getPreviousVector(0, 1); float currentDistance = current.getLength(); float previousDistance = previous.getLength(); if (currentDistance-previousDistance != 0) { scale *= currentDistance / previousDistance; } angle -= VMVector2D.getSignedAngleBetween(current, previous); /*angleCount=angleCount+angle;*/ } } invalidate(); } catch(Exception exception) { // Log.d("VM", exception.getMessage()); } return true; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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