Android图片旋转
16lz
2021-12-04
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);}}
运行结果如下所示:(第一张是图像旋转之前,第二张是图像旋转之后)
更多相关文章
- 计算器布局基于GridLayout
- android .xml文件 布局文件
- Android绘图之ComposeShader,PorterDuff.mode及Xfermode(13)
- [Android]Android高级UI开发系列教程(二) - Android绘制教程
- android中xml文件注意事项
- Android: 向最强看齐, 反编译 愤怒的小鸟.apk
- android专栏
- Android: 向最强看齐, 反编译 愤怒的小鸟.apk
- Android: 向最强看齐, 反编译 愤怒的小鸟.apk