绘制图片

来源:互联网 发布:陈子豪淘宝店铺 编辑:程序博客网 时间:2024/04/28 10:36

绘制图片

public class CustomView extends View {    public CustomView(Context context, AttributeSet attrs) {        super(context, attrs);    }    @SuppressLint("DrawAllocation")    @Override    protected void onDraw(Canvas canvas) {        super.onDraw(canvas);        // 图片工厂解析资源文件        Bitmap bitmap = BitmapFactory.decodeResource(getResources(),                R.drawable.ic_launcher);        Paint paint = new Paint();        paint.setColor(Color.RED);        canvas.drawBitmap(bitmap, 0, 30, paint);        Rect src = new Rect(20,20,20,20);        Rect dst = new Rect(10, 10, 10, 10);        // 裁剪图片        //canvas.drawBitmap(bitmap, src, dst, paint);        if(bitmap!=null){            bitmap.recycle();        }    }}

这里写图片描述

0 0