Amir Heshmati Amir Heshmati - 1 year ago 79
Android Question

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


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);
canvas.drawBitmap(tempTextBitmap, matrix, new Paint());;
return fullTextBitmap;

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download