Search code examples
androidandroid-bitmapbitmapregiondecoder

Loading 26 letter images from a PNG stripe using BitmapRegionDecoder


In a word game app I am trying to load 26 letter tiles from a 6205 x 240 PNG image:

private Paint mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);

mStripe = BitmapFactory.decodeResource(
    context.getResources(), R.drawable.big_english);
int h = mStripe.getHeight();
mSrc = new Rect(0, 0, h, h);
mDst = new Rect(0, 0, h, h);

canvas.drawBitmap(mStripe, mSrc, mDst, mPaint);

On the real device (Moto G) this fails with (I guess 1.5x downscaled from drawables-xxhdpi):

OpenGLRenderer Bitmap too large to be uploaded into a texture (4137 x 160; max=4096x4096)

and the letter images aren't displayed (the dragged tile appears to be empty):

Moto G photo

So I would like to use BitmapRegionDecoder to load 240 x 240 bitmaps, but as an Android programming newbie (and I have searched around too) I still have 2 questions please:

  1. How to load a R.drawable.big_english - there is no suitable constructor?
  2. Can I somehow use isShareable here - given the fact that I load 26 letters?

Solution

  • Bitmapfonts for android http://examples.javacodegeeks.com/android/games/canvas/using-bitmap-fonts/

    You should also google for bit map fonts. There are a few more implementations and examples.

    For gl there's an implementation in libgdx http://www.codehead.co.uk/blog/android-bitmap-font-renderer-text-scaling-feature/