Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Images in the 'drawable' folder are resized automatically?

Tags:

android

I have a 1280x720px image in the res/drawable folder (not the drawable-hdpi, drawable-ldpi, etc. folder). But at runtime the size is 2560x1440px. How is this possible? Does android resize the images in the drawable folder?

Here is the code:

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.start_image_left);
    int h = bitmap.getHeight(), w = bitmap.getWidth();

I'm testing this on a Motorola Moto G gen2.

like image 336
kovacs lorand Avatar asked Dec 03 '14 19:12

kovacs lorand


People also ask

What is the preferred image format for Drawables?

Supported file types are PNG (preferred), JPG (acceptable), and GIF (discouraged). App icons, logos, and other graphics, such as those used in games, are well suited for this technique.

How do you change drawable size on android?

Once you import svg file into Android Studio project, you are going to see <vector> resource then just change the size as you want by width , height attributes. viewportWidth and viewportHeight is to set size for drawing on virtual canvas.

Where is the drawable folder in Android Studio?

In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the drawable folder contains the different types of images used for the development of the application.


1 Answers

There's really no reason you should ever put a bitmap into the root drawable directory. It should typically be used for XML drawables only. Bitmaps in the drawable directory will essentially be handled as if they were in drawable-mdpi (scaled up proportionally for other densities).

If your goal is to have a bitmap image that is the same pixel size on all densities, you need to put it in drawable-nodpi. This will cause it to not be scaled.

like image 160
Kevin Coppock Avatar answered Oct 09 '22 12:10

Kevin Coppock