package com.gyarmy.imgetest02; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.os.Bundle; import android.os.Environment; import android.view.View; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView img_src; private ImageView img_dst; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img_src = (ImageView) findViewById(R.id.img_src); img_dst = (ImageView) findViewById(R.id.img_dst); } public void getPIC(View v){ //加载原图 String path = Environment.getExternalStorageDirectory().toString(); path = path+"/Download/02.jpg"; Bitmap fileImg = BitmapFactory.decodeFile(path); img_src.setImageBitmap(fileImg); //依照原图,重新绘图 Bitmap dstBitmap = Bitmap.createBitmap(fileImg.getWidth(), fileImg.getHeight(), fileImg.getConfig()); Canvas cas = new Canvas(dstBitmap); Paint paint = new Paint(); //设置规则 Matrix matrix = new Matrix(); //缩放 matrix.setScale(0.4f, 0.4f); //旋转 matrix.setRotate(40, dstBitmap.getWidth()/2f, dstBitmap.getHeight()/2f); //画图 cas.drawBitmap(fileImg, matrix, paint); img_dst.setImageBitmap(dstBitmap); } }
0则评论给“图片旋转”