2016-04-05 10 views
0

ビットマップにはテキストのみが含まれているため、ビットマップの幅と高さはテキストの幅と高さと数式によって決まります。私はキャンバスを使用してビットマップ内のテキストを回転させる

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) 

を使用してテキストを回転させたときに、今、これは回転の中心が間違っているだけでなく、明らかに

enter image description here

起こるものです。 I'vはcanvas.translateを使用しようとしたとの結果が良くなっているが、彼らはまだ正しくありません:

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

テキストが長くなる場合、結果は最悪

+0

完全に異なる方法を使用する必要がある場合は、私に教えてください。 –

答えて

0

を取得し、私はhereを見つけました次のコードはキャンバス内のビットマップを回転させます:

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

これを試しましたか?

+0

はい、私は正確にはコードではなく行列を試してみましたが、動作しませんでした[これ](http://stackoverflow.com/questions/8712652/rotatingキャンバス・イン・アンドロイドの画像) あなたが提案したコードもうまくいかない –

+0

どのように見えますか? – KimKulling

+0

http://imgur.com/o0dNiil 奇妙なエフェクトを無視しても、テキストはまだ外に出る@KimKulling –