Androidは画像のズーム反転機能を実現する.ターン

2289 ワード

from http://topmanopensource.javaeye.com/blog/674727
package com.easyway.andorid.hello;

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;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout.LayoutParams;

/**
 * Android         
 * @author longgangbai
 * @date 2010-5-24
 * @version 1.0
 * @since JDK6.0
 */
public class ImageViewAndorid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         //       
         setTitle("       ");
         //   LinearLayout    lly
         LinearLayout lly=new LinearLayout(this);
         //             icon.png ,        res/drawable ,
         //       itfunz.bmp,          
         Bitmap bmpOrg=BitmapFactory.decodeResource(getResources(), R.drawable.icon);
         //          
         int width=bmpOrg.getWidth();
         int height=bmpOrg.getHeight();
         
         int newWidth=400;
         int newheight=400;
         //           
         float sw=((float)newWidth)/width;
         float sh=((float)newheight)/height;
         //         Matrix  
         Matrix matrix=new Matrix();
        
         matrix.postScale(sw,sh);
         //       
         matrix.postRotate(30);
         //  30*
         Bitmap resizeBitmap=Bitmap.createBitmap(bmpOrg,0,0,width,height,matrix,true);
        
         //         
         BitmapDrawable bmp=new BitmapDrawable(resizeBitmap);
        
         //  Bitmap   Drawable  ,       ImageView ImageButton 
         ImageView imageView=new ImageView(this);
         //  ImageView   
         imageView.setImageDrawable(bmp);
         //        
         imageView.setScaleType(ScaleType.CENTER);
         //          
         lly.addView(imageView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
         //  ImageView      
         setContentView(lly);
    }
}


転載先:https://www.cnblogs.com/bobystudy/articles/1773770.html