質問

I'm having problems while trying to rotate a picture with java android canvas.drawImage. I'm doing a little game, and I'm painting different pictures on the screen using my drawImage function. However now I want to rotate some little images, I have created a function called drawMirroredImage for this. However now this little images don't appear on the same place.

Here is my code:

public void drawImage(Image Image, int x, int y) {
    canvas.drawBitmap(((AndroidImage) Image).bitmap, x, y, null);
}

public void drawMirroredImage(Image Image, int x, int y) {
    canvas.save();
    canvas.scale(-1.0f, 1.0f);
    canvas.drawBitmap(((AndroidImage) Image).bitmap, x - canvas.getWidth(), y, null);
    canvas.restore();   
}

Anyone knows what I'm doing wrong?

Lot of thanks for helping

役に立ちましたか?

解決

Try this code for rotating image view.

    Matrix mx=new Matrix();
myimageView.setScaleType(ScaleType.MATRIX); 
mx.postRotate((float) angle, pivX, pivY);
myimageView.setImageMatrix(mx);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top