Rotate image along with touch to fix point in android - android

I am trying to rotate image in image view coresponding with touch to fix pivote pint of image . i have seen many of example but i dont clear with all of it .somebody have idea ..how can do it this this ?

Since there is no code or details provided about where the bitmap is drawn i assume its at the center of the screen. You can rotate the canvas on center point like this
double rotationAngleRadians = Math.atan2(currentX - centerX, centerY - currentY);
rotationAngleDegrees = (int) Math.toDegrees(rotationAngleRadians );
canvas.rotate(rotationAngleDegrees , centerX, centerY);

Related

Drawing a circle on a particular pixel of image

I have drawn a circle in a canvas with image in it on click event in one activity. And I have taken the x and y coordinates of that circle. In another activity i want to draw the same circle at the same position but the image size is not same so it is pointing to different position. So, how can achieve this?
The new position of circle (newX, newY) must move at same ratio that image size change.
newX = oldX * (newImageWidth / oldImageWidth)
newY = oldY * (newImageHeight / oldImageHeight)
You may want to change the size of the circle same way.

rotate image around a center of another image

I have rotated a dial around its center with the helop from the link below:
http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-a-rotating-dialer/
Now I have an icon beside the dialer and I need to rotate it around the dialer, along with the dialer in a circular path.
private void rotateLogo(float degrees){
Matrix nMatrix = new Matrix();
Bitmap peopleOrg = BitmapFactory.decodeResource(getResources(), R.drawable.peoplelogo);
float translateX = dialerWidth / 2 - dialerWidth / 2;
float translateY = dialerHeight / 2 - dialerWidth / 2;
nMatrix.preTranslate(-turntable.getWidth()/2, -turntable.getHeight()/2);
nMatrix.postRotate(degrees, translateX, translateY);
nMatrix.postTranslate(turntable.getWidth()/2, turntable.getHeight()/2);
Bitmap peopleScale = Bitmap.createBitmap(peopleOrg, 0, 0, peopleOrg.getWidth(), peopleOrg.getHeight(), nMatrix, true);
peopleLogo.setImageBitmap(peopleScale);
peopleLogo.setImageMatrix(nMatrix);
}
This just causes the image to rotate around its own center and not around the dialer's center point.
I cant find out where i am wrong :(
Updates
I basically need the logo to move in a circular path and be a clickable view.
Tried using rotateAnim but the view doesnt animate and i have trouble getting the onclick event.
Would like any help that can rotate the same using matrices
Try only rotate with peopleOrg width and height.
nMatrix.postRotate(degrees, peopleOrg.getWidth()/2, peopleOrg.getHeight()/2);
Update :
Now that you let me know that your logo should be a clickable view, merging the logo image with your dialer is not applicable. To rotate the logo view around the center of dialer you should be actually calculating the (top,left) point for your logo view and moving it around, than just rotating it.
Use sine and cosine functions to get the point on the circumference of an imaginary circle for drawing your logo view.
This post will help you with calculations : How do I calculate a point on a circle’s circumference?

Android - Rotate Dial [duplicate]

How can I rotate a bitmap (not a view or canvas) around its center point when the user touches it and drags it?
I have tried loads of examples on stack overflow and none appear to work.
So far I have:
double r = Math.atan2(posX - dial.getWidth() / 2, dial.getHeight() / 2 - posY);
rotation = (int) Math.toDegrees(r);
Create Matrix then set rotate via setRotate(degrees). Then use this matrix when creating new Bitmap: Bitmap.createBitmap(..)

Rotate in Android [duplicate]

How can I rotate a bitmap (not a view or canvas) around its center point when the user touches it and drags it?
I have tried loads of examples on stack overflow and none appear to work.
So far I have:
double r = Math.atan2(posX - dial.getWidth() / 2, dial.getHeight() / 2 - posY);
rotation = (int) Math.toDegrees(r);
Create Matrix then set rotate via setRotate(degrees). Then use this matrix when creating new Bitmap: Bitmap.createBitmap(..)

Android - Rotate image around center point?

How can I rotate a bitmap (not a view or canvas) around its center point when the user touches it and drags it?
I have tried loads of examples on stack overflow and none appear to work.
So far I have:
double r = Math.atan2(posX - dial.getWidth() / 2, dial.getHeight() / 2 - posY);
rotation = (int) Math.toDegrees(r);
Create Matrix then set rotate via setRotate(degrees). Then use this matrix when creating new Bitmap: Bitmap.createBitmap(..)

Categories

Resources