我想创建可以导入位图并在位图上绘制的活动。 现在我可以导入但我不能在位图上绘画。
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
//mCanvas.drawColor(0xffffffff);
}
protected void onDraw(Canvas canvas) {
//canvas.drawColor(0xffffffff);
canvas.drawBitmap(bitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
谢谢。
答案 0 :(得分:0)
从您的评论“绘制路径显示一段时间”,我猜测用户的绘画显示但很快就会消失。这是因为您不断在用户绘图上重绘位图。添加一个布尔检查以确保只绘制一次位图:
Boolean first = true;
protected void onDraw(Canvas canvas){
if(first) canvas.drawBitmap(bitmap, 0, 0, mBitmapPaint);
first = false;
canvas.drawPath(mPath, mPaint);
}