title: Drawing bitmaps with alpha channel: please advise... (some solutions and speed issues)
body: <p>I have a rather big number of small bitmaps (100+, size about 40x40) each one have some opaque and some transparent parts and i need to paint them respecting these areas.</p>
  
  <p>Bitmaps are in ARGB format, 888(rgb) plus a 256bit alpha channel, standard like in PNG format.</p>
  
  <p>The only (working) way i found to draw them is the following approach:</p>
  
  <ol>
  <li>create a bitmap (ARGB_8888)</li>
  <li>fill the bitmap with the raw data</li>
  <li>extract the alpha layer from the bitmap</li>
  <li>create a BitmapShader (RGB_565) based on the original bitmap</li>
  <li><p>Create a paint for the bitmap which uses the created shader</p></li>
  <li><p>Then paint the alpha mask using the paint with the special BitmapShader.</p></li>
  </ol>
  
  <p>The initialization code is run only once, of course:</p>
  
  <pre><code>void initializeTile( int t ){
  // Allocate the bitmap:
  Bitmap original_data = Bitmap.createBitmap( tile_w, tile_h, Bitmap.Config.ARGB_8888);
  // Fill with raw data (this is actually native C++ code):
  populateBitmap( original_data );
  // Get the alpha mask:
  tile_mask[ t ] = original_data.extractAlpha();
  // Create the bitmap shader:
  tile_data = original_data.copy( Bitmap.Config.RGB_565, false);
  // Create the shader:
  BitmapShader shader = new BitmapShader(tile_data, CLAMP, CLAMP);
  
  // Create the paint:
  tile_paint[ t ] = new Paint();
  tile_paint[ t ].setDither(true);
  tile_paint[ t ].setAntiAlias(true);
  tile_paint[ t ].setFilterBitmap(true);
  tile_paint[ t ].setShader( shader );
  }
  </code></pre>
  
  <p>And the paint code is the most simple possible, and it's in the main draw loop:</p>
  
  <pre><code>void paintTile(t){
  canvas.drawBitmap( tile_mask[ t ],  tile_x[ t], tile_y[ t], tile_paint[ t] );
  }
  </code></pre>
  
  <p>Now, on phones like the Ideos (Android 2.2) it run smooth and fine, but on other phones like the top-end Samsung Galaxy SII (Android 2.3) it's crappy and slow. This does not make much sense to me... </p>
  
  <p>So, what do you think of this approach? Are there better, faster, ways to achieve the same result?</p>
  
  <p>And, why do you think it's so slow on modern, fast hardware? Is there any ways to improve it?</p>