我想在我拍的照片上画画。绘图工作没有绘制图片,但如果我绘制位图,我只看到位图但 n 绘图出现。我尝试了很多,但似乎没有任何帮助。提前致谢。
private class myView extends View implements OnTouchListener{
File root = Environment.getExternalStorageDirectory();
Path path;
ArrayList<Path> _graphics = new ArrayList<Path>();
Bitmap myBitmap;
Paint myPaint;
public myView(Context context) {
super(context);
File file = new File(root, "temp.jpg");
myBitmap = null;
if (file.exists()) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
myBitmap = setBitmap(BitmapFactory.decodeFile(new File(root,
"temp.jpg").getPath(), options));
}
myPaint = new Paint();
myPaint.setColor(Color.GREEN);
myPaint.setStyle(Paint.Style.STROKE);
myPaint.setStrokeWidth(3);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(myBitmap, 0, 0, null);
for (Path path : _graphics) {
canvas.drawPath(path, myPaint);
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
path = new Path();
path.moveTo(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());
_graphics.add(path);
}
return true;
}
}