Image Transformation to apply rotation, drag and scaling at same time - android

I want to apply rotation, drag and scaling on Image at same time. Image drag and Scaling works fine but as soon as I apply rotation Image quality lost. Please give me any example which have rotation, move and scaling on Image at same time and Image quality should not lost after applying transformation

Look at MapsDemo in the Maps API extension. It implements a smoothed canvas in order to rotate maps. They do this by turning on filtering in the Paint used to draw the image.
private final Paint mSmooth = new Paint(Paint.FILTER_BITMAP_FLAG);
Some quality will always be lost in rotation because the mapping from source to destination pixels can be perfect only at the 90 degree points.
BTW, instead of drag I think you mean translation.

Related

Rotation drawing point on image in Android

First of all I'm sorry for my English language because it is not perfect.
This is my code to moving, zooming image:
http://www.mediafire.com/view/6572cu99v9942xd/SandboxView.java
I want to rotate image also with that point called x=250 and y=200, How can I do that with saving zoom and move image?
call Canvas.concat(Matrix) before drawing anything on the canvas

Matrix: limiting translate and scale in android

I am drawing an image in android using canvas.
I'm using surfaceview's ontouch method to let the user scale and move the image.
I can already limit the scaling but I have a problem limiting the translate.
I can limit translate only if the scale of the matrix is in its original form, but if the
scale is changed I'm having a problem limiting its translation.

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

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.

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.

Where does Android.Graphics.Camera set its X,Y, and Z axis when canvas is set to a bitmap?

I want to get a bitmap and manipulate it in the following way:
I have created an empty bitmap, on this bitmap, I drew what I needed. Now I need to distorted in a way similar to this because I will then be drawing the whole thing ontop of another bitmap. Think of it as applying a texture to a box. The box simply being a picture of a box. The way that I see myself doing this is creating bitmaps off the main bitmap and drawing them onto the final bitmap through a matrix modified by Graphics.Camera.getMatrix().
I already have this working, but my problem is understanding just exactly how to manipulate the camera. I don't know where the camera creates its X Y and Z axis within the matrix. Or where does the matrix get applied. Or just how it all comes together.
When drawing on canvas set to view, I know I can rotate the canvas and draw from there to create a straight diagonal line, for example in a game engine to draw a projectile acting on two vectors. And I know when working on OpenGL, there is a state machine approach and I can imagine where the matrix is in 3D space. But I just don't understand how Camera, Matrix, and bitmap all relate.
From what I've looked up, I managed to set up the basic solution to this but havent been able to understand just exactly how to tweak this in order to get the right rotations. I have read the documentation but it doesn't really explain the relationship between Camera, Matrix, and canvas beyond the fact that Camera modifies a matrix and then canvas can draw something based on that matrix.
Can anyone explain how I would go about doing what I have in the picture? I already know that I'll be creating a bitmap from region in original bitmap. Then combining the two, to create what is on the right column , and then rotating the canvas/bitmap and getting another bitmap from green section and repeat the whole thing again.
Thanks
Camera is just a utility class that generates a Matrix you can use on Canvas. The generated Matrix contains the appropriate transform. You said it yourself:
it doesn't really explain the relationship between Camera, Matrix, and
canvas beyond the fact that Camera modifies a matrix and then canvas
can draw something based on that matrix.
That's all there is to it really :)

Categories

Resources