I found a solution to my problem by myself (It was my bad )!
In fact, I have a method loading automatically resources as Texture, by rescaling the Bitmap to the nearest power of 2. But for some devices, Android recommands to load a picture 512x512 as a 1024x1024 picture (when using Context.getResources().getDrawable(R.id.......)).
So I had to find another way to retrieve the real picture size instead of using Drawable methods. Which is done now by using the BitmapFactory!
Explanations through the code:
Wrong way to scale automatically pictures:
Warning : getIntrinsicWidth and getIntrinsicHeight (Drawable methods) returns only Android advise about width and height the texture should have. In my case, these methods return an integer (between 1024 and 2047) for a picture 512x512 for some devices only...
Better way to scale pictures:
In fact, I have a method loading automatically resources as Texture, by rescaling the Bitmap to the nearest power of 2. But for some devices, Android recommands to load a picture 512x512 as a 1024x1024 picture (when using Context.getResources().getDrawable(R.id.......)).
So I had to find another way to retrieve the real picture size instead of using Drawable methods. Which is done now by using the BitmapFactory!
Explanations through the code:
Wrong way to scale automatically pictures:
Code Select
String resourceName = context.getResources().getResourceEntryName(resourceID);
Drawable drawable = context.getResources().getDrawable(resourceID);
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
// set to highest width that is a power of 2 (troncate)
int new_width = Integer.highestOneBit(width);
int new_height = Integer.highestOneBit(height);
// ..... (I removed code asserting that texture is not already loaded)
Texture tex = new Texture(BitmapHelper.rescale(
BitmapHelper.convert(drawable), new_width, new_height));
Warning : getIntrinsicWidth and getIntrinsicHeight (Drawable methods) returns only Android advise about width and height the texture should have. In my case, these methods return an integer (between 1024 and 2047) for a picture 512x512 for some devices only...
Better way to scale pictures:
Code Select
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(context.getResources(), resourceID, options);
int width = options.outWidth;
int height = options.outHeight;
// set to highest width that is a power of 2 (troncate)
int new_width = Integer.highestOneBit(width);
int new_height = Integer.highestOneBit(height);
// ..... (I removed code asserting that texture is not already loaded)
Texture tex = new Texture(BitmapHelper.rescale(
BitmapHelper.convert(context.getResources().getDrawable(resourceID)), new_width, new_height));