How to determine in which direction a bitmap has to be rotated? - android

How can I determine in which direction and how far I have to rotate the image? I use Android Canvas to draw the line and the arrow image.
canvas.drawBitmap(arrow_direction, leftpos,rightpos,null);
The image is always shown as it is. The image shows clearly that I have to rotate it 90 degree to the left.
I know I can rotate the image with
Matrix rotator = new Matrix();
rotator.reset();
rotator.postRotate(degree);
But I don't know how to calculate the value for degree to rotate the arrow? I know only the coordinates of the two red points. So I think it might be possible to calculate it with this two points, but I don't know how.
In another way how can determine on which side of the image is the end point of the line? In the example it is on the right side, therefore I know that I have to rotate the image -90 degree.

Related

ImageView Rotation with different pivot

I'd like to rotate an ImageView with a different pivot in Android Studio.
This is how it rotates when it's -45 degree by default pivot(centre).
So, when we do animation, it works in a fixed image area such as a fan or a windmill.
But what I want to do is like this.
The red point is the new pivot that I want. In this way, it will take over 4 times bigger areas if it rotates 360 degrees.
How can I implement this?

Capturing android touch drawing coordinates as paths

Using an example found here:
http://www.vogella.com/tutorials/AndroidTouch/article.html I'm able to draw a path every time a finger touches the screen and that works great, Is there any way that I can capture that drawn path and reproduce it in another view in other coordinates? Like capturing the full drawn image and reproducing it scaled in a segment of the other view?
Sorry for my bad english
You can save your drawn image and save it as a bitmap. Then you can scale it with Matrix or Canvas and redraw it by calling to where you want to draw

Rotate image with its objects

Firstly I'm using Android application to rotating image with selected angle. that image has drawable lines by canvas.
I'm able to rotate the image but the line not.
I want to rotate and draw lines with new directions.

Android Rotating a set of bitmaps around a common pivot point

I am trying to create a game like Jigsaw Puzzle. I am using a class that extends View and in its draw method, I am drawing different bitmap pieces. When user tap a bitmap, I rotates that bitmap by 90 degree angle. Its working perfectly. But user combines some bitmap pieces and then rotate the group, the bitmaps rotate around their center point destroying the group structure.
My question is how to rotate a set of bitmaps around a common pivot point so that when a group of bitmaps rotate, it retains its shape structure?
I am assuming that you have each of the pieces center-weighted which is causing your problem.
On possibility is to have the background be a center weighted object or to look at background and declare the center as the point of rotation.
Then, calculate the approximate box size of each jigsaw piece (this could be dynamic based on if you are using Zoom). to figure out its placement on the screen as bitmap objects in Draw().
Now, imagine a line being draw from the center to the edge of the screen being rotated to get your angle.
So, based on this new information, you would need to calculate your new angle for each center weighted object (jigsaw piece) based off of the angle set by the center of the screen rotation. Each piece would have a different angle of rotation on its axis because of the new line or angle of rotation set by the center of the screen.
This is more of an algorithm/calculation than programming, more specifics on your issue would help.

How do I rotate a canvas without disturbing the coordinate system in Android?

I am trying to rotate a canvas with canvas.rotate and move an object on it at the same time. The problem is that with the rotation, the coordinate system of the canvas rotates as well, so I get cases when my object is supposed to be moving along the y axis, but the y axis is rotated on place of the x axis. It is a mess. Is there a way to go around this?
It's using matrix math; if you do things in the opposite order (translate then rotate, or vice versa), you'll get the opposite effect.
Also, use SetMatrix(null) to clear the matrix to the identity between operations; not sure if that's the kind of mess you're having trouble with.

Categories

Resources