title: RuntimeException when converting graphics to RGB_565
body: <p>I have an occasional crash report from Google Play Console for my game which I am finding difficult to fix. It's relatively rare, but it's the cause of a few 1-star reviews so far.</p>
  
  <p>Thousands of times this code works fine, it's only rarely that it causes a fatal error (it's on start-up so it crashes out immediately for the user). It doesn't give me the reason why throwIfCannotDraw trips out.</p>
  
  <p>Any help greatly appreciated!</p>
  
  <p>Edit: I think it could be a timing problem as it's at start-up and there's loads going on in other threads - loading/initialising ad networks, analytics, Google Play Services, etc. Anyone have experience with this?</p>
  
  <pre><code>    java.lang.RuntimeException: 
        at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1301)
        at android.graphics.Canvas.drawBitmap(Canvas.java:1356)
  </code></pre>
  
  <p>Here's the top few Devices causing the crash:</p>
  
  <pre><code>Galaxy Tab Pro 12.2 (v2wifi)        6   14.0%
  Galaxy Tab Pro 10.1 (picassowifi)   5   11.6%
  Galaxy Tap Pro 8.4 (mondrianwifi)   4   9.3%
  Galaxy Note 10.1 (lt033g)       3   7.0%
  Galaxy TabS 8.4 (klimtwifi)     3   7.0%
  Galaxy S7 Edge (hero2lte)       3   7.0%
  Zmax Pro (urd)              2   4.7%
  Galaxy Note5 (noblelte)         2   4.7%
  </code></pre>
  
  <p>The Android version doesn't seem to be a cause:</p>
  
  <pre><code>Android 5.1 14  32.6%
  Android 7.0 12  27.9%
  Android 4.4 7   16.3%
  Android 6.0 6   14.0%
  </code></pre>
  
  <p>The code:</p>
  
  <pre><code>bitmapTMP1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.map_charset);
  
  bitmapTMP2 = Bitmap.createScaledBitmap(bitmapTMP1,
          (int) (MAP_CHARSET_SX * scaleFactor),
          (int) (MAP_CHARSET_SY * scaleFactor),
          false);
  
  bitmapTMP1.recycle();
  
  bitmapMapCharset = Bitmap.createBitmap( bitmapTMP2.getWidth(), bitmapTMP2.getHeight(), Bitmap.Config.RGB_565 );
  
  Canvas c = new Canvas();
  c.setBitmap(bitmapMapCharset);
  
  c.drawBitmap(bitmapTMP2,0,0,null); //HERE - Causes RuntimeException sometimes 
  
  bitmapTMP2.recycle();
  </code></pre>