您的位置:首页 > 移动开发 > Android开发

android 在Bitmap上进行绘图操作

2015-09-10 19:57 375 查看
需要借助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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: