title: Adding an Image to a Canvas in Android
body: <p>Good Day Everyone</p>
  
  <p>I was hoping if you could help me understand the concepts of understanding how to add an image into a canvas on a OnTouchEvent implemented on a View. So far, this is what i've come up with.<br />
  <strong>parent</strong> is the Activity where in this customized view is instantiated and is added into.</p>
  
  <pre><code>@Override
  protected void onDraw(Canvas canvas)
  {
      // TODO Auto-generated method stub
      super.onDraw(canvas);
  }
  
  public void insertImage()
  {
      if (parent.selected_icon.contentEquals("image1"))
      {
          image = getResources().getDrawable(R.drawable.image1);
      }
      else if (parent.selected_icon.contentEquals("image1"))
      {
          image = getResources().getDrawable(R.drawable.image2);
      }
      else if (parent.selected_icon.contentEquals("iamge3"))
      {
          image = getResources().getDrawable(R.drawable.image3);
      }
  
      Rect srcRect = new Rect(0, 0, image.getIntrinsicWidth(), 
              image.getIntrinsicHeight());
      Rect dstRect = new Rect(srcRect);
  
      Bitmap bitmap = Bitmap.createBitmap(image.getIntrinsicWidth(), 
              image.getIntrinsicHeight(), Bitmap.Config.ALPHA_8);
  
      Canvas canvas = new Canvas();
      canvas.drawBitmap(bitmap, srcRect, dstRect, null);
      invalidate();
  }
  </code></pre>