[英]Rotation and translation bitmap simultaneously
I'm creating a live wallpaper in which I want to rotate image 1 on canvas continuously while it moves left to right and so on. 我正在创建一个动态壁纸,在其中我想在画布上左右移动图像1的同时连续旋转图像1。 I was able to move it from left to right but on applying rotation it gives it in the center with no rotation.
我能够从左到右移动它,但是在应用旋转时,它没有旋转地位于中心。 My code is given below.
我的代码如下。 I used animations but it has caused error in the live wallpaper.
我使用了动画,但它导致动态壁纸出错。
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 degree=0;
c.drawBitmap(backgroundImage, 0, 0, null);
Matrix transform = new Matrix();
// transform.setTranslate(100, 100);
// transform.preRotate(degree,75 ,100);
// canvas.drawBitmap(bitmap, transform, null);
transform.setRotate(degree, x, y);
c.drawBitmap(image1, transform, null);
//canvas.rotate(-90);
if(x>width+100){
// assign initial value to start with
x=-130;
}
// change the x position/value by 1 pixel
x=x+4;
degree+=45;
c.restore();
}
}
I don't see you calling c.save(); 我看不到您在调用c.save(); when you call c.restore() it needs to be paired with a previous c.save().
当您调用c.restore()时,它需要与先前的c.save()配对。
From the api on restore(): This call balances a previous call to save(), and is used to remove all modifications to the matrix/clip state since the last save call. 从api上的restore()上:该调用平衡了对save()的先前调用,并且用于删除自上次save调用以来对矩阵/剪辑状态的所有修改。 It is an error to call restore() more times than save() was called.
多次调用restore()而不是调用save()是一个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.