我是靠谱客的博主 真实微笑,这篇文章主要介绍Android 图片旋转实现的两种方法的比较,现在分享给大家,希望可以做个参考。

转载请标明出处:http://blog.csdn.net/nmyangmo/article/details/73506752

图片旋转的方法有两种(旋转ImageView所在布局暂不考虑),这两种分别是动画和使用Matrix(齐次变换矩阵)。 
我们想要达到的目标是旋转长图(非正方形),甚至长宽比例很夸张那种。想达到的效果是以图片中心为原点旋转,旋转过程中不失真,不缺失。

首先先看一下动画的效果

复制代码
1
2
3
4
5
6
7
8
Animation rotateAnimation = new RotateAnimation(0f, getRoll(i), Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setFillAfter(true); rotateAnimation.setDuration(0); rotateAnimation.setRepeatCount(0); rotateAnimation.setInterpolator(new LinearInterpolator()); rotateAnimation.setDetachWallpaper(true); photoView.startAnimation(rotateAnimation);


效果图: 
è¿éåå¾çæè¿°

然后我们再看一下Matrix的方法旋转

复制代码
1
2
3
4
5
6
7
8
Matrix matrix = new Matrix(); //旋转图片 动作 matrix.setRotate(getRoll(i));//旋转角度 width = bitmap.getWidth(); height = bitmap.getHeight(); // 创建新的图片 Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); BitmapDrawable bitmapDrawable = new BitmapDrawable(resizedBitmap); imageView.setImageDrawable(bitmapDrawable);

效果图: 

è¿éåå¾çæè¿°

两种方法的对比: 
性能方面:动画的方式不用操作一个bitmap和生bitmap对象,性能比较好 
效果:采用动画的方式长图在旋转过程中会出现缺失,而Matrix不会 
总结:如果图片是正方形选择动画的实现方式,如果是长方形且不允许缺失则选择Matrix

转载请标明出处:http://blog.csdn.net/nmyangmo/article/details/73506752

Demo下载地址:http://download.csdn.net/detail/nmyangmo/9875840
 

 

最后

以上就是真实微笑最近收集整理的关于Android 图片旋转实现的两种方法的比较的全部内容,更多相关Android内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部