Code example for ByteBuffer

Methods: capacity, clear

0
 
    /* round up */ 
    int requiredCapacity = ((width * height - 1) | 0x3fff) + 1;
 
    /* check if the existing buffer is already large enough */ 
    if (pixels == null || pixels.capacity() < requiredCapacity)
      pixels = ByteBuffer.allocate(requiredCapacity);
    else if (pixels != null)
      pixels.clear();
  } 
 
  public int[] getTextTextureGL(String text) {
    getTextBounds(text);
 
    // draw text into a bitmap 
    Bitmap bmp = Bitmap.createBitmap(extent[0], extent[1],
                                     Bitmap.Config.ALPHA_8);
    bmp.eraseColor(Color.TRANSPARENT);
    paint.setColor(Color.WHITE);
    Canvas canvas = new Canvas(bmp);
    canvas.drawText(text, 0, -paint.getFontMetricsInt().ascent, paint);