문제

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