OutOfMemoryError / creating a background image with the dimensions of a view
<p>Every once in a while I get a crash report for my app that looks like this:</p>

<pre><code>java.lang.OutOfMemoryError: bitmap size exceeds VM budget(Heap Size=18119KB, Allocated=15536KB, Bitmap Size=31040KB)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:695)
at myPackage.MyApp.MyView.onSizeChanged(MyView.java:46)
</code></pre>

<p>I couldn't reproduce this problem so far and have no information on which devices this problem occurs.</p>

<p>What exactly does "Bitmap Size=31040KB" mean? Is my app really trying to create a 30MB bitmap?
I'm creating a background image for a custom SeekBar component that should have the same size of the view (9-patch not suitable for my use-case). Here's the overridden method of SeekBar that produces the error:</p>

<pre><code>@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    if (w &lt;= 0 || h &lt;= 0)
        return;

    LayerDrawable ld = (LayerDrawable)getContext().getResources().getDrawable(R.drawable.colorpicker);

    Bitmap output = Bitmap.createBitmap(w,
                h, Config.ARGB_8888);

    // code that draws the image, left that out here

    BitmapDrawable bmD = new BitmapDrawable(output);
    ld.setDrawableByLayerId(android.R.id.background, bmD);
    setProgressDrawable(ld);

    super.onSizeChanged(w, h, oldw, oldh);
}
</code></pre>

<p>Line 46 is the one where the bitmap is created.
The view stretches across the whole screen and has the default height of a SeekBar, so in the worst case the bitmap should maybe require about 80KB...any ideas what might be wrong?</p>
