Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimate (Zoom and Translate) a part of image on android canvas view
    primarykey
    data
    text
    <p>I have an image e.g. the image shown below: <img src="https://i.stack.imgur.com/O5muj.jpg" alt="sample image source 3dwallpapers"></p> <p>This image has two parts part 1 of size width <em>W</em> and height <em>L</em> and part 2 (smaller part) of width <em>w</em> and height <em>h</em> (call part one as source and part 2 as destination). Let the coordinates of the 1st rectangle be (measured from top left corner): top:100 left: 10 right: 200 bottom: 300 and the coordinates of the 2nd rectangle be (as measured from top left corner): top 50 left: 500 bottom: 100 right: 700</p> <p>I want to animate from source to destination such that the image translates and zooms in from source to destination.</p> <p>So my first screen would look like: <img src="https://i.stack.imgur.com/PqPeq.png" alt="enter image description here"></p> <p>and my second image would look like: <img src="https://i.stack.imgur.com/0wwpC.png" alt="enter image description here"></p> <p>How do I tween between these two ? My code (without animation) looks like as follows:</p> <pre><code>public class SuperGame extends View implements OnGestureListener { int sreenHeight, screenWidth; int drawCount = 0; Bitmap bg; public SuperGame(Context context, Bitmap bmp) { this.screenWidth = getContext().getResources().getDisplayMetrics().widthPixels; this.screenHeight = getContext().getResources().getDisplayMetrics().heightPixels; bg = BitmapFactory.decodeResource(getResources(),R.drawable.bg_img); } @Override /* this function triggers the image change */ public boolean onDown(MotionEvent e) { invalidate(0,0,screenWidth, screenHeight); return true; } @Override public void onDraw(Canvas canvas) { Rect dest = new Rect(0,0,screenWidth, screenHeight); if (count==0) //draw the first image part { count=1; Rect src = new Rect(100,10,200,300);//coordinates of rectangle 1 canvas.drawBitmap(bg, src, dest, new Paint()); } else //draw the second image part - (I'd like to show movement/ transition between these) { Rect src = new Rect(50,500,100,700);//coordinates of rectangle 2 count=0; canvas.drawBitmap(bg, src, dest, new Paint()); } } } </code></pre> <p>How to I animate the transition (which involves zoomin as well as translation)?</p>
    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.
    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