title: How to draw Bitmap fast in onDraw() method in canvas android
body: <p>I am trying to draw a marker on single tap method in android. when i draw the marker it will draw but it will take more time to draw i.e 30-40 milliseconds some times it takes 2-3 seconds. Here is my code for class in which i have draw method.</p>
  
  <pre><code>public class MyItemizedOverlay extends ItemizedOverlay&lt;OverlayItem&gt; {
  
      private ArrayList&lt;OverlayItem&gt; overlayItemList = new ArrayList&lt;OverlayItem&gt;();
  
      public MyItemizedOverlay(Drawable pDefaultMarker,
              ResourceProxy pResourceProxy) {
          super(pDefaultMarker, pResourceProxy);
      }
  
      @Override
      public void draw(Canvas canvas, MapView mapView, boolean arg2) {
          super.draw(canvas, mapView, arg2);
  
          // ---translate the GeoPoint to screen pixels---
          Point screenPts = new Point();
          mapView.getProjection().toPixels(p, screenPts);
  
          // ---add the marker---
          Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                  R.drawable.pin_annotation_darkblue);
          Bitmap bmp1 = BitmapFactory.decodeResource(getResources(),
                  R.drawable.pin_annotation_green);
          Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),
                  R.drawable.pin_annotation_bue);
          Bitmap bmp3 = BitmapFactory.decodeResource(getResources(),
                  R.drawable.pin_annotation_light);
          Bitmap bmp4 = BitmapFactory.decodeResource(getResources(),
                  R.drawable.pin_annotation_light);
          Bitmap bmp5 = BitmapFactory.decodeResource(getResources(),
                  R.drawable.pin_annotation_light);
          Bitmap bmp6 = BitmapFactory.decodeResource(getResources(),
                  R.drawable.pin_annotation_light);
          if (count == 1) {
              int caller = getIntent().getIntExtra("button", 0);
              switch (caller) {
              case R.id.btMap:
                  canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
                  bmp.recycle();
                  break;
              case R.id.imageButton1:
                  canvas.drawBitmap(bmp1, screenPts.x, screenPts.y - 50, null);
                  bmp1.recycle();
                  break;
              case R.id.imageButton2:
                  canvas.drawBitmap(bmp2, screenPts.x, screenPts.y - 50, null);
                  bmp2.recycle();
                  break;
              case R.id.imageButton3:
                  canvas.drawBitmap(bmp3, screenPts.x, screenPts.y - 50, null);
                  bmp3.recycle();
                  break;
              case R.id.imageButton4:
                  canvas.drawBitmap(bmp4, screenPts.x, screenPts.y - 50, null);
                  bmp4.recycle();
                  break;
              case R.id.imageButton5:
                  canvas.drawBitmap(bmp5, screenPts.x, screenPts.y - 50, null);
                  bmp5.recycle();
                  break;
              case R.id.imageButton6:
                  canvas.drawBitmap(bmp6, screenPts.x, screenPts.y - 50, null);
                  bmp6.recycle();
                  break;
              }
          }
          // Bitmap bmp = BitmapFactory.decodeResource(getResources(),
          // R.drawable.pin_annotation_green);
          // if (count == 1) {
          // canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null);
          // }
  }
  </code></pre>