Android中,我们可以使用矩阵实现图像旋转

首先,创建一个布局xml文件:

<?xml version="1.0" encoding="utf-8"?><br /><LinearLayout android:id="@+id/LinearLayout01"<br />android:layout_width="fill_parent"<br />android:layout_height="fill_parent"<br />xmlns:android="http://schemas.android.com/apk/res/android"<br />android:background="#ffffff"<br />android:gravity="center"><br /><ImageView android:id="@+id/ImageView01"<br />android:layout_width="wrap_content"<br />android:layout_height="wrap_content"<br />android:src="@drawable/refresh" /><br /></LinearLayout><br />



创建主Activity类文件:

public class ExampleApp extends Activity{private ImageView img;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);img=(ImageView)findViewById(R.id.ImageView01);Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.refresh);// Getting width & height of the given image.int w = bmp.getWidth();int h = bmp.getHeight();// Setting post rotate to 90Matrix mtx = new Matrix();mtx.postRotate(90);// Rotating BitmapBitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);img.setImageDrawable(bmd);}}


运行结果如下所示:(第一张是图像旋转之前,第二张是图像旋转之后)



更多相关文章

  1. 计算器布局基于GridLayout
  2. android .xml文件 布局文件
  3. Android绘图之ComposeShader,PorterDuff.mode及Xfermode(13)
  4. [Android]Android高级UI开发系列教程(二) - Android绘制教程
  5. android中xml文件注意事项
  6. Android: 向最强看齐, 反编译 愤怒的小鸟.apk
  7. android专栏
  8. Android: 向最强看齐, 反编译 愤怒的小鸟.apk
  9. Android: 向最强看齐, 反编译 愤怒的小鸟.apk

随机推荐

  1. 在Android中引入Java8的lambda表达式
  2. Android4.0:统一标准强行安装默认主题Holo
  3. 硬件访问服务4之Android硬件访问服务框架
  4. Android深度探索(卷1):安装C/C++交叉编译环
  5. Android构建过程简述
  6. ThreadLocal原理
  7. 在 Kotlin 中使用 Logger 打印 OkHttp 网
  8. Android中写文本文件的方法
  9. 对Android平台Linux部分的初步理解
  10. Android应用程序注冊广播接收器(registerR