android > 图片旋转
16lz
2021-01-23
T3Activity.java
package t3.com;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Matrix;import android.graphics.drawable.BitmapDrawable;import android.os.Bundle;import android.widget.ImageView;public class T3Activity extends Activity { /** Called when the activity is first created. */private ImageView iv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); iv = (ImageView)findViewById(R.id.iv); Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(), R.drawable.t); int width = bitmapOrg.getWidth(); int height = bitmapOrg.getHeight(); // 创建操作图片用的matrix对象 Matrix matrix = new Matrix(); matrix.postRotate(270);//旋转度数 Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true); BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); iv.setImageDrawable(bmd); } //\\}
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" ><RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_centerInParent="true" android:layout_height="wrap_content" android:background="@android:color/transparent" /></RelativeLayout></LinearLayout>
更多相关文章
- Android Binder进程间通信-ServiceManager代理对象的获取过程
- Android中如何使用Intent在Activity之间传递对象[使用Serializab
- Android Activity之间传递类对象
- 3-14 servlet 传出对象给 Android
- android 对象保存到SP
- android TabHost 对象报错
- Android wifi的WifiInfo对象详解
- Android之JAVASe基础篇-面向对象-IO(九)