title: Android: Draw image on canvas where the user touches
body: <p>so I have a canvas, and I would like a certain image (Lets say image.png) to appear where the user touches. What would I use? OnTouch?</p>
  
  <p>Can someone help me out? Here is my canvas class below. Right now I have a few random images and shapes drawn, but they happen right away, not when someone touches like I would like it.</p>
  
  <p>Thanks in advance! </p>
  
  <p>public class MyView extends View </p>
  
  <pre><code>private Canvas canvas;
  private Bitmap bitmap;
  
  public MyView(Context context) {
      super(context);
  
  
  
      }    
  
  protected void onSizeChanged(int curw, int curh, int oldw, int oldh) {
      if (bitmap != null) {
          bitmap .recycle();
      }
      canvas= new Canvas();
      bitmap = Bitmap.createBitmap(curw, curh, Bitmap.Config.ARGB_8888);
      canvas.setBitmap(bitmap);
  
  
  }
  public void destroy() {
      if (bitmap != null) {
          bitmap.recycle();
      }
  }
  
  public void onTouch(Canvas canvas) {
      Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.test);
      canvas.drawColor(Color.TRANSPARENT);
      canvas.drawBitmap(_scratch, 0, 0, null);
  }
  
  public void onDraw(Canvas canvas) {
    //draw onto the canvas
  
  
       Bitmap _scratch1 = BitmapFactory.decodeResource(getResources(), R.drawable.spacecat);
       canvas.drawColor(Color.TRANSPARENT);
       canvas.drawBitmap(_scratch1, 0, 0, null);
  
  
  
       Paint myPaint = new Paint();
       myPaint.setStrokeWidth(4);
       myPaint.setColor(0xFF097286);
       canvas.drawCircle(240, 40, 30, myPaint);
       myPaint.setColor(0xFFF07222);
       Point p1 = new Point();
       Point p2 = new Point();
       p1.x = 0;
       p1.y = 0;
       p2.x = 40;
       p2.y = 55;
       canvas.drawLine(p1.x, p1.y, p2.x, p2.y, myPaint);
       float[] pts = new float[8];
       pts[0] = 100;
       pts[1] = 5;
       pts[2] = 97;
       pts[3] = 9;
       pts[4] = 90;
       pts[5] = 15;
       pts[6] = 84;
       pts[7] = 20;
       myPaint.setColor(0xFF40FF40);
       myPaint.setStrokeWidth(9);
       myPaint.setAntiAlias(true);
       canvas.drawPoints(pts, myPaint);
  
  
       myPaint.setColor(0xFFF0FF00);
       myPaint.setStrokeWidth(4);
       myPaint.setStyle(Paint.Style.STROKE);
       canvas.drawCircle(110, 150, 100, myPaint);
  
  }}
  </code></pre>