Question

So the scenario is that I have a surfaceView of size 640 x 480 on which I am showing on camera preview. Now I draw a something vertically on the screen. After that I am rotating the canvas using

canvas.rotate(90, getWidth()/2, getHeight/2);

Once I do that, I am expecting my drawing to be scaled and drawn horizontally. It does draw it horizontally but it is not scaling it according the width and height.

Here is the pictorial example explanation to help you understand better. https://lh4.googleusercontent.com/-2wlImCt0m88/UcHzhKUSGBI/AAAAAAAAB9Y/bGNMOTu9DqM/s1440/canvas_rotation.png

Is there a way or an algorithm by which I can rotate the canvas and then scale it accordingly? let me know if you need any further explanation.

Thanks in advance.

Was it helpful?

Solution

Well so I figured out the solution to it. What we can do is that we can use

canvas.scale( newX, newY, pivotX, pivotY);

/*
 * Where 
 * newX = oldX * (newWidth/oldWidth);
 * newY = oldY * (newHeight/oldHeight);
 * pivotX = same as before;
 * pivotY = same as before;
*/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top