Search code examples
androidimagescale

Load and scale images in raw folder


Suppose I have an image, named "image.jpg" inside res/raw/ folder.
Then I load it with :

InputStream imageIS = this.getResources().openRawResource(R.raw.image);
Bitmap myImage = BitmapFactory.decodeStream(imageIS);

Looks like they're not scaled according to screen densities (ldpi/mdpi/hdpi/etc..).
How can I scale those images according to different screen densities ?

(I know that there is an easy way doing so, by placing it into drawable folder, but for some reasons, I'd like to place my image in raw folder)


Solution

  • By placing it in the raw folder, you've told Android you want the image exactly as it is. If you really want the system to scale your image according to size and density of the device, you have to place it in one of the drawable folders under res. If you just like to use the raw folder, then you apparently just like to keep your images as they are.