android 图片旋转

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android 图片旋转相关的知识,希望对你有一定的参考价值。

参考技术A android UI之ImageView旋转的几种方式

Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.ic_launcher)).getBitmap();
Matrix matrix = new Matrix();
matrix.setRotate(90);
Bitmap new = Bitmap.create(bitmap,0,bitmap.getWidth(),0,bitmap.getHeight(),matrix);
image.setBitmapResource(bitmap);
如果程序不断获取新的bitmap重新设置给ImageView的话,那么bitmap在不断旋转,又不回收内存,浪费大大哒,不推荐使用。

可以通过在xml中设置ImageView的属性来实现,如

android:rotation="90" //写死固定方向没问题
,这样。
动态调用如下:

iv.setPivotX(image.getWidth()/2);
iv.setPivotY(image.getHeight()/2);//支点在图片中心
iv.setRotation(90);

可以使用ImageView配合属性动画实现,如
iv.animate().rotation(90); //会好看一下,只有第一次加载时是这样的

或者普通动画
Animation rotateAnimation = new RotateAnimation(lastAngle, progress, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1);
rotateAnimation.setFillAfter(true);
rotateAnimation.setDuration(50);
rotateAnimation.setRepeatCount(0);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateImage.startAnimation(rotateAnimation);

Matrix matrix=new Matrix();
rotateImage.setScaleType(ScaleType.MATRIX); //required
matrix.postRotate((float) progress, pivotX, pivotY);
iv.setImageMatrix(matrix);

以上是关于android 图片旋转的主要内容,如果未能解决你的问题,请参考以下文章

PS中如何旋转图片

android怎么实现图片旋转

android 图片旋转

js设置图片随机旋转角度

ps问题,怎么旋转图片里的东西

css怎么设置图片定点旋转?