Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get the image matrix co ordinates in android?

I am developing an application where is included crop functionality and in this I'm blocked at below scenario.

The scenario:

Crop overlay is not circulating the whole image when we apply straightening to the image if we change the crop overlay, ratio also is not working.

I got the code from google but it is related to matrix, I have tried using matrix, but here I need to find the coordinates(edges) of matrix to move the overlay.

How to find it? If anyone has any idea please help me...

I added the image to explain the problem enter image description here

Thanks in advance..
I am using the below code but I didn't get the exact coordinates of the matrix

RectF r = new RectF(); 
 mymatrix.mapRect(r);
 Rect rect = 
 new Rect((int)r.left,int)r.top,int)r.right+width,int)r.bottom+height);
like image 242
Ashok Avatar asked Jun 25 '15 12:06

Ashok


1 Answers

You should not use mapRect if you are applying rotation on your matrix. My advice is to figure out the 4 initial points representing each rectangle edge (the image itself) and use mapPoints instead.

Lets say you have an image 200px wide and 200px tall with its top left corner positioned at origin (0,0).

If you rotate this image from its center (100,100) 45 degrees and then scale it 200% from its center we will have the following scenario:

    //original image coords
    float[] points = {
            0f, 0f, //left, top
            200f, 0f, //right, top
            200f, 200f, //right, bottom
            0f, 200f//left, bottom
    };

    Matrix matrix = new Matrix();
    //rotate 45 degrees from image center
    matrix.postRotate(45f, 100f, 100f);
    //scale 200% from center
    matrix.postScale(2f, 2f, 100f, 100f);

    //get the new edges coords
    matrix.mapPoints(points);

After calling matrix.mapPoints(points) the points array will have the updated coords. This means points[0], points[1] will have the new left top image coord and so on.

The even indices represents the abscissas and the odd indices represents the ordinates on the points array.

like image 52
tato.rodrigo Avatar answered Oct 31 '22 17:10

tato.rodrigo