图片的放大
图片的缩小
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv);//iv布局中设置的图片
Matrix matrix = new Matrix();
matrix.setScale(2, 2);//缩放比例 宽高都是原来的2倍
//1.买一张纸 纸张是原来的2倍大小,但材质是一样的
Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth()*2, bitmap.getHeight()*2, bitmap.getConfig());//配置跟原来一样
//2.买个画板
Canvas canvas = new Canvas(newBitmap);//画板上放刚才买的纸
//3.临摹作画 需要画笔
Paint paint = new Paint();
paint.setColor(Color.BLACK);
//第一个参数:你想临摹的图片
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(newBitmap);
图片的缩小
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.meinv);
Matrix matrix = new Matrix();
matrix.setScale(0.5f, 0.5f);
//1.买一张纸
Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getConfig());//纸张大小跟图片缩放比例一样
//2.买个画板
Canvas canvas = new Canvas(newBitmap);
//3.临摹作画
Paint paint = new Paint();
paint.setColor(Color.BLACK);
canvas.drawBitmap(bitmap, matrix, paint);
iv.setImageBitmap(newBitmap);