Search code examples
androidbitmapimage-rotation

how to find the position of a rotated text?


For example this is my image

enter image description here

i know the height and the width of the text and how much it has been rotated (the angle) i also know where the top left corner of the text is if it was not rotated for example:

enter image description here

i also know the position of the text center which text rotate around and that position doesn't change in the rotation

now i need to know if the user tap on the image whether it has been on the text or not if yes i also would need to know the offset

EDIT

here is the code responsible for rotating and positioning the text bitmap

public Bitmap getFullTextBitmap2(Bitmap hostBitmap) {
    Bitmap tempTextBitmap = getTextBitmap(); // getting the bitmap which only contain the text and has the height and width of the text
    Bitmap fullTextBitmap = hostBitmap.copy(hostBitmap.getConfig(), true);
    Canvas canvas = new Canvas(fullTextBitmap);
    Matrix matrix = new Matrix();
    matrix.setRotate(tilt - 180, textWidth / 2, textHeight / 2);
    matrix.postTranslate(position.getLeft(), position.getTop());
    if (isSelected) {
        Canvas textCanvas = new Canvas(tempTextBitmap);
        textCanvas.drawColor(selectedColor);
        textCanvas.save();
        textCanvas.restore();
    }
    canvas.drawBitmap(tempTextBitmap, matrix, new Paint());
    canvas.save();
    canvas.restore();
    return fullTextBitmap;
}

Solution

  • As @pskink suggested I used:

    Matrix#mapPointes
    

    But I used it to undo the the user touch input and compare it with none-rotated bitmap.