当我旋转位图时,它会旋转,但它会在屏幕上不断移动并同时旋转。我想让它在中心旋转?我的代码如下。
try {
c = holder.lockCanvas();
// clear the canvas
c.drawColor(Color.BLACK);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
if (c != null) {
int width=c.getWidth();
int height=c.getHeight();
c.drawBitmap(backgroundImage, 0, 0, null);
Matrix transform = new Matrix();
Matrix transform1=new Matrix();
transform.setRotate(degree, width/2,height/2);
c.drawBitmap(image1, transform, null);
//canvas.rotate(-90);
degree+=5;
c.restore();
}
}
最佳答案
试试这个代码..
c = holder.lockCanvas();
c.drawColor(Color.BLACK);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
if (c != null)
{
int width=c.getWidth();
int height=c.getHeight();
c.drawBitmap(backgroundImage, 0, 0, null);
Matrix matrix = new Matrix();
float px = width/2;
float py = height/2;
matrix.postTranslate(-image1.getWidth()/2, -image1.getHeight()/2);
matrix.postRotate(degree);
matrix.postTranslate(px, py);
c.drawBitmap(image1, matrix, paint);
degree+=5;
c.restore();
}
关于java - 位图的定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23372278/