0

コードに問題があります。テキストを回転させようとするとすべてが機能しますが、キャンバスを復元したいので呼び出しますcanvas.restore();

私がそれをすると、私のアプリはすぐにシャットダウンします...

私のコードの一部:

画面の一部に触れる:

if (wahrheitswert1  == true) { 
    x = 480;
    y = 100;    

    // draw bounding rect before rotating text
    Rect rect = new Rect();
    canvas.translate(x, y);

    // undo the translate
    canvas.translate(-x, -y);
    // rotate the canvas on center of the text to draw
    canvas.rotate(-180, x + rect.exactCenterX(), y + rect.exactCenterY());
    // draw the rotated text
    canvas.drawText("Spieler1 touch", x, y, paint);
    //undo the rotate
    //canvas.restore();
    wahrheitswert1 = false;
    canvas.restore();
}

ビットマップを復元しないと、背景画像が画面の他のサイトからコピーされます。ご協力いただきありがとうございます

4

2 に答える 2

1

キャンバスをあまり使用していませんが、復元する前にコンテキストを保存する場所がわかりません。最初にコンテキストを保存する必要があるコンテキストで復元を行うことは間違いありません。

于 2011-09-13T22:29:46.807 に答える
0

電話する必要があります

Canvas.save()

キャンバスを回転する前に。Canvas.save() を呼び出すことで、いつでも Canvas を復元できます。以下のコードを修正しました。

if (wahrheitswert1  == true) { 
    x = 480;
    y = 100;   

    canvas.save();

    // draw bounding rect before rotating text
    Rect rect = new Rect();
    canvas.translate(x, y);

    // undo the translate
    canvas.translate(-x, -y);
    // rotate the canvas on center of the text to draw
    canvas.rotate(-180, x + rect.exactCenterX(), y + rect.exactCenterY());
    // draw the rotated text
    canvas.drawText("Spieler1 touch", x, y, paint);
    //undo the rotate
    //canvas.restore();
    wahrheitswert1 = false;
    canvas.restore();
}

私も同じ問題を抱えていて、うまくいきました。

于 2013-09-17T07:11:43.640 に答える