Android開發新手,我的應用程序是用多種顏色從顏色選擇器中選擇畫布(具有位圖)的繪製路徑。之前繪製的路徑顏色正在使用畫布上的新路徑顏色進行更新。任何在幫助我,這是我的代碼.........畫布上用多種顏色繪製線條
@Override
public void run() {
// TODO Auto-generated method stub
while (locker) {
canvas = null;
try {
if (!holder.getSurface().isValid()) {
continue;
}
canvas = holder.lockCanvas();
draw(canvas);
} finally {
if (canvas != null) {
holder.unlockCanvasAndPost(canvas);
}
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// synchronized (thread.getSurfaceHolder()) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
path = new Path();
path.moveTo(event.getX(), event.getY());
path.lineTo(event.getX(), event.getY());
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
path.lineTo(event.getX(), event.getY());
} else if (event.getAction() == MotionEvent.ACTION_UP) {
path.lineTo(event.getX(), event.getY());
paths.add(path);
}
return true;
// }
}
/**
* This method deals with paint-works. Also will paint something in
* background
*/
private void draw(Canvas canvas) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.bell);
// canvas.drawColor(Color.CYAN);
canvas.drawBitmap(bitmap, 20, 20, mPaint);
// canvas.drawPath(mPath, mPaint);
for (Path path : paths) {
// canvas.drawPoint(graphic.x, graphic.y, mPaint);
canvas.drawPath(path, mPaint);
}
}
}
http://stackoverflow.com/questions/3616676/how-to-draw-a-line-in-android –