android 在Bitmap上进行绘图操作

来源:互联网 发布:老炮儿网络剧 编辑:程序博客网 时间:2024/05/22 17:44

    需要借助canvas,canvas是一块画板,可以在上面画画。

    内容比较简单,直接上源码:

    需要注意的是,如果Bitmap以 bmp = BitmapFactory.decodeResource(this.getBaseContext().getResources(), R.drawable.ic_launcher);将会报如下bug:

Immutable bitmap passed to Canvas constructor

    这是因为资源文件不能被直接修改,需要copy一份才行。

 Bitmap bmp = BitmapFactory.decodeResource(getResources(),            R.drawable.ic_launcher).copy(Bitmap.Config.ARGB_8888, true);Canvas canvas = new Canvas(bmp);Paint paint = new Paint();paint.setColor(Color.BLUE);canvas.drawLine(0, 0, bmp.getWidth(), bmp.getHeight(), paint);//canvas.drawBitmap(bmp,0, 0, paint);ImageView view = (ImageView)findViewById(R.id.my_view);view.setImageBitmap(bmp);


0 0
原创粉丝点击