Zeichnen auf einer Leinwand mit Bitmap als Hintergrund

Ich versuche, auf dem Sie zeichnen ein Bild, das ich genommen habe.
Die Zeichnung funktioniert, ohne das Bild gezeichnet, aber wenn ich zeichne die bitmap, sehe ich nur die bitmap, aber n Zeichnung kommt.
Habe viel versucht, aber nichts scheint zu helfen.
Vielen Dank im Voraus.

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;
    }
}
  • rufen invalidate() in onTouch
  • Auch ich hatte konfrontiert eine ähnliche situation vor. Ich hatte zu geben, ein Hintergrundbild für mein Spiel, das war auf einem surfaceView. Das hintergrund-Bild zu erhalten löschen, wenn Sie auf Sie zu ziehen.
  • invalidate() nicht etwas ändern...
  • Ich danke Ihnen allen für Ihr wertvolles feedback.
InformationsquelleAutor ghaas | 2013-01-25
Schreibe einen Kommentar