0

The bitmap only contain the text so the width and the height of the bitmap are determined by text's width and height and some math. now when i rotate the text using

canvas.rotate(tilt - 180, bitmap.getWidth() / 2, bitmap.getHeight() / 2);
//the seek bar has a range of 0 to 360 so in order to get the right tilt i need to use (tilt - 180) instead of (tilt)

this is what happen

enter image description here

well obviously center of the rotation is wrong. I'v tried to use canvas.translate and the result have got better but they are yet not correct:

    float actualTilt = Math.abs(tilt - 180);
    actualTilt = (actualTilt >= 90 && actualTilt != 180) ? 90 - actualTilt % 90 : actualTilt;
    if (actualTilt == 180) actualTilt = 0;
    // by above statements i make sure actualTilt is less than 90 and it's values are 0,1,...89,90,89,88,...0
    float v = actualTilt / 90;
    canvas.translate((-(textWidth / 2) * v), (textHeight / 2) * v);
    //i don't understand the above statement either but this is the result

enter image description here

if texts get longer the result get even worst

Amir Heshmati
  • 550
  • 1
  • 8
  • 19

1 Answers1

0

I found here the following codeto rotate a bitmap in a canvas:

Matrix matrix = new Matrix();
matrix.setRotate(angle, imageCenterX, imageCenterY);
yourCanvas.drawBitmap(yourBitmap, matrix, null);

Have you tried this out?

Community
  • 1
  • 1
KimKulling
  • 2,654
  • 1
  • 15
  • 26
  • yes i did try matrix not that code exactly but it didn't work [this](http://stackoverflow.com/questions/8712652/rotating-image-on-a-canvas-in-android) the code you've suggested also doesn't work – Amir Heshmati Apr 05 '16 at 07:20
  • How does it looks like? – KimKulling Apr 05 '16 at 08:08
  • http://imgur.com/o0dNiiL ignoring the weird effect the text still goes out of bound @KimKulling – Amir Heshmati Apr 05 '16 at 08:19
  • Which center of rotation have you used? It does not look correctly for me in the moment.Have you tried to use a local rotation? – KimKulling Apr 05 '16 at 09:36
  • center of the text bitmap. thanks for your time but I've solved the issue by tilting the whole bitmap as i was unable to tilt the text only... it has resulted in another issue but it would be off topic to talk about. i'll try to post my own answer thanks again... – Amir Heshmati Apr 05 '16 at 09:42