Android 旋转背景资源图像视图
我正在创建Imageview并使用矩阵进行旋转。但背面不旋转支持图像 我正在旋转图像。帮帮我Android 旋转背景资源图像视图,android,Android,我正在创建Imageview并使用矩阵进行旋转。但背面不旋转支持图像 我正在旋转图像。帮帮我 Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.a); Display d = getWindowManager().getDefaultDisplay(); int x = d.getWidth(); int y = d.getHeight();
Bitmap myBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.a);
Display d = getWindowManager().getDefaultDisplay();
int x = d.getWidth();
int y = d.getHeight();
ImageView img1 = (ImageView) findViewById(R.id.img1);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(myBitmap, y, x,
true);
Matrix matrix = new Matrix();
matrix.postRotate(-45); // anti-clockwise by 90 degrees
Bitmap rotatedBitmap = Bitmap
.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(),
scaledBitmap.getHeight(), matrix, true);
img1.setImageBitmap(rotatedBitmap);
img1.setBackgroundResource(color.white);
下面是我用于将图像旋转到90度的代码
if(oldAngle == 0){
newAngle = oldAngle + 90;
}
else if(oldAngle == 90)
newAngle = oldAngle - 90;
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
int centerX = layoutParams.leftMargin + (view.getWidth()/2);
int centerY = layoutParams.topMargin + (view.getHeight()/2);
RotateAnimation animation = new RotateAnimation(oldAngle, newAngle, centerX, centerY);
animation.setDuration(0);
animation.setRepeatCount(2);
animation.setFillAfter(true);
view.startAnimation(animation);
oldAngle = newAngle;
希望它能帮助您……要旋转图像吗?