笔记如下
如图
2018-03-18_085026.png
- 实现步骤:
1.首先动态获取图片
2.画图片
1.准备画纸(大小参照原图)
Bitmap copyBitmap = Bitmap.createBitmap(srcBitmap.getWidth(),srcBitmap.getHeight(),srcBitmap.getConfig());
2.准备画板,将画纸放到画板上
Canvas canvas = new Canvas(copyBitmap);
3.准备画笔
Paint paint = new Paint();
4.按照一定规则,矩阵规则,缩放,位移规则在这里
Matrix matrix = new Matrix();
//缩放一半
matrix.setScale(0.5f,0.5f);
5.按照规则将图像画到画纸上
canvas.drawBitmap(srcBitmap,matrix,paint);
完整源码:按钮的点击
public void opts(View v){
String path = "storage/emulated/0/6.jpg";
Bitmap srcBitmap = BitmapFactory.decodeFile(path);
iv_src.setImageBitmap(srcBitmap);
//1.准备画纸(大小参照原图)
Bitmap copyBitmap = Bitmap.createBitmap(srcBitmap.getWidth(),srcBitmap.getHeight(),srcBitmap.getConfig());
//2.准备画板,将画纸放到画板上
Canvas canvas = new Canvas(copyBitmap);
//3.准备画笔
Paint paint = new Paint();
//4.按照一定规则,矩阵规则,缩放,位移规则在这里
Matrix matrix = new Matrix();
matrix.setScale(0.5f,0.5f);
//5.按照规则将图像画到画纸上
canvas.drawBitmap(srcBitmap,matrix,paint);
iv_dest.setImageBitmap(copyBitmap);
}
网友评论