安卓:一个角度旋转图像的ImageView [英] Android: Rotate image in imageview by an angle

查看:951
本文介绍了安卓:一个角度旋转图像的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的code。通过一个角度旋转的ImageView一个图像。有没有更简单的,更简单的方法可用。

  ImageView的IV =(ImageView的)findViewById(imageviewid);
TextView的电视=(TextView中)findViewById(txtViewsid);
矩阵垫=新的Matrix();
位图BMAP = BitmapFactory.de codeResource(getResources(),imageid);
mat.postRotate(的Integer.parseInt(度)); ===>角度被旋转
位图bMapRotate = Bitmap.createBitmap(BMAP,0,0,bMap.getWidth(),bMap.getHeight(),垫,真正的);
iv.setImageBitmap(bMapRotate);
 

解决方案

另一种简单的方式来旋转的ImageView
更新:
所需进口:

 进口android.graphics.Matrix;
进口android.widget.ImageView;
 

code:(假设的ImageView 角度 pivotX &安培; pivotY 已定义)

 矩阵矩阵=新的Matrix();
imageView.setScaleType(ImageView.ScaleType.MATRIX); //需要
matrix.postRotate((浮动)的角度,pivotX,pivotY);
imageView.setImageMatrix(矩阵);
 

此方法不需要创建一个新的位图每次。

  

请注意:要旋转的ImageView 上的 ontouch 的在运行时可以   设置的 onTouchListener 的关于的ImageView &放大器;通过将最后两个旋转   线;在上述code(即 postRotate 的矩阵放大器设置上的的ImageView 的)   在你触摸监听器部分的 ACTION_MOVE 的一部分。

I am using the following code to rotate a image in ImageView by an angle. Is there any simpler and less complex method available.

ImageView iv = (ImageView)findViewById(imageviewid);
TextView tv = (TextView)findViewById(txtViewsid);
Matrix mat = new Matrix();
Bitmap bMap = BitmapFactory.decodeResource(getResources(),imageid);
mat.postRotate(Integer.parseInt(degree));===>angle to be rotated
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,bMap.getWidth(),bMap.getHeight(), mat, true);
iv.setImageBitmap(bMapRotate);

解决方案

Another simple way to rotate an ImageView:
UPDATE:
Required imports:

import android.graphics.Matrix;
import android.widget.ImageView;

Code: (Assuming imageView, angle, pivotX & pivotY are already defined)

Matrix matrix = new Matrix();
imageView.setScaleType(ImageView.ScaleType.MATRIX);   //required
matrix.postRotate((float) angle, pivotX, pivotY);
imageView.setImageMatrix(matrix);

This method does not require creating a new bitmap each time.

NOTE: To rotate an ImageView on ontouch at runtime you can set onTouchListener on ImageView & rotate it by adding last two lines(i.e. postRotate matrix & set it on imageView) in above code section in your touch listener ACTION_MOVE part.

这篇关于安卓:一个角度旋转图像的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆