android > 图片旋转

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>
 

猜你喜欢

转载自mft.iteye.com/blog/1725478