Android - Draw on top of the image

b2.setOnClickListener(new OnClickListener() { public void onClick(View v) { setContentView(R.layout.new_main); String editTextStr = text.getText().toString(); Toast msg = Toast.makeText(getBaseContext(),"/sdcard/Stored_Images/" + editTextStr + ".jpg", Toast.LENGTH_LONG); msg.show(); Bitmap bmp = BitmapFactory.decodeFile("/sdcard/Stored_Images/" + editTextStr + ".jpg"); ImageView img = (ImageView) findViewById(R.id.ImageView01); img.setImageBitmap(bmp); } }); 

In the above code, the image on the screen that is saved on the SD card is displayed.

 Canvas c = holder.lockCanvas(); c.drawARGB(255,0,0,0); onDraw(c); holder.unlockCanvasAndPost(c); 

This code creates a canvas for drawing (black screen).

I want to combine the two to set / display the image as a canvas so that I can draw it. Therefore, if I take a picture of someone’s face, I want to be able to display this image so that I can draw a mustache or something on it.

+6
source share
2 answers

You are probably better off creating a canvas by adding a bitmap to it and then processing your custom touch / drawing.

 Bitmap bmp = BitmapFactory.decodeFile("/sdcard/Stored_Images/" + editTextStr + ".jpg"); mCanvas = new Canvas(bmp); 

then for the drawing ... how did you do it, but if not, you can check fingerPaint samples from the demos api, which demonstrate drawing on the canvas (on which you would draw your image at this point.)

+4
source

You can customize ImageView and draw a picture on your image in onDraw (canvas canvas)

Example:

In your activity:

1) create a bitmap from the image

2) set Bitmap for customized ImageView

  a) create object for customized ImageView 

MyImageView view = new MyImageView (this);

  b) set the bitmap view.setImageBitmap(bmp); 

MyImageView.java:

 class MyImagView extends ImageView{ //constructor public MyImageView(Context context){ } //onDraw() @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); //drawlines where ever you want using canvas.drawLine() } @Override public void setImageBitmap(Bitmap bm) { super.setImageBitmap(bm); } } 
+1
source

All Articles