INNER CODE UNIT · Java
loadRGBAImage
githubhaohao/NDK_OpenGLES_3_0 · app/src/main/java/com/byteflow/app/MainActivity.java:572
private Bitmap loadRGBAImage(int resId) {
InputStream is = this.getResources().openRawResource(resId);
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(is);
if (bitmap != null) {
int bytes = bitmap.getByteCount();
ByteBuffer buf = ByteBuffer.allocate(bytes);
bitmap.copyPixelsToBuffer(buf);
byte[] byteArray = buf.array();
mGLRender.setImageData(IMAGE_FORMAT_RGBA, bitmap.getWidth(), bitmap.getHeight(), byteArray);
}
}
finally
{
try
{
is.close();