Android Studio resizes my Images when I import them - android

I need to add an image as an Activity Background so.
I right clicked res folder > New > Image Asset
and I imported a picture under Launcher Icons category. But my pictures have been resized and the quality has been lost. Is there anyway of importing the original image and its quality without having to resize it through Android Studio?
Also, how would I reference it in my XML? I'm used to eclipse and what I usually do is:
android:src="#drawable/MyPicture"
ALSO, How would this affect screen sizes since I'm avoiding resizing? The original image size 900 x 678

You are importing them, as you said, under Launcher Icons category, which will automatically try to resize them to 48dp (and the respective px for the resolution density). You probably just want to navigate to your project and copy paste the image into the drawable folder and then refer to it as you mentioned in your question.
android:src="#drawable/MyPicture"
Your other option is to create different sized backgrounds and copy paste them into their respective drawable-mdpi, drawable-hdpi, drawable-xhdpi, drawable-xxhdpi, and drawable-xxxhdpi folders.
Android will try to scale your image to fit the screen unless you specify a scaleType: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

Related

Do I need to use all of drawable, drawable-mdpi, drawable-hdpi, drawable-xhdpi, drawable-xxhdpi & drawable-xxxhdpi?

I realise that Android will try it's best if it does not find an icon in the required folder but I see someplaces they suggest all of the above and in others they don't include drawable ?
So should I populate drawable as well if all the others are filled with my tab icon images?
If you use a VectorDrawable, you don't need to add a Resource for every density (mdpi, xhdpi etc). VectorDrawable is supported since API 21 (Lollipop) or with Support Library (or AndroidX).
For simple types of images (usually icons), you can avoid creating separate images for each density by using vector graphics. Because vector graphics define the illustration with geometric line paths instead of pixels, they can be drawn at any size without scaling artifacts.
For images (PNG) on the other hand, you must add proper icons for every density because Android will try to scale the images (so they can proportionally occupy same area in all devices). When scaling, the image may become blurred reducing the quality of your UI.
To provide good graphical qualities on devices with different pixel densities, you should provide multiple versions of each bitmap in your app—one for each density bucket, at a corresponding resolution. Otherwise, Android must scale your bitmap so it occupies the same visible space on each screen, resulting in scaling artifacts such as blurring.
You can read more HERE and HERE
EDIT
Maybe, you don't need to duplicate ALL icons. A lot of factors can lead to different experiences such as using wrap_content or a specific dimension to control the icon size or even using a different scaleType in your ImageView. So, maybe, you can start by adding icons for xhdpi or xxhdpi folders only and check your screen in different screen (small display, large displays, low-resolution displays, high-resolution displays etc). Then, you can "duplicate" only the necessary icons... But if your project or APK size is relatively small, don't mind to duplicate the icons.
There's even some online tools to generate the assets for every density from a single PNG such Android Asset Studio website..
If you are adding all resolution drawable icon like :
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxdpi
then you need not to add any extra icons on drawable folder
because all the device resolution covers under the above drawable folders

Android: Same Image needs to be added in all drawable folders?

I am directly adding images in drawable folders and it is coming fine with ImageView tag android:src="#drawable/image_name" but I wonder what to do with the other drawable folders as shown below.
Do I need to add same image in all drawable folders or my way of adding images in drawable folders is wrong?
Please help me!
The image is same, but the size should be different for each folders.
If you add the image only in drawable folder, same image will be loaded for all screen resolutions. So for eg: if the image size is small, this may result in bad image quality.
You can find a similar question here
I use Android studio plugin Android Drawable Importer
All these drawable folders represent different android phone densities. The best folder to put your images is drawable-xxhdpi as android automatically downscale or upscale the images depending on your devices density and most phones these days are on xxhdpi density.
If you put a image in drawable folder only there are chances that image may get distorted(as it upscales) in xxxhdpi density.
If you are putting images in xxhdpi ,make sure you create your images acc. to xxhdpi resolution.
If you don't feel the image is looking right in some phones than check the density of that phone and put an image in that specific density folder acc. to it's size(reduced or increased).
Just put it in the drawable folder, no need to put it in other drawable-... folders because those folders and contents inside are created automatically by android studio.

How to import high resolution image to android studio?

So whenever I import an image as an image asset it is always blurry. When asked what type of asset is it I always select launcher. (Because thats the only way.)
I'm using the drawable as part of a selector, one image when pressed and another when not. Is there another way I can put an image in android studio?
Use Draw 9-patch tool to create bitmap images that automatically resize to accommodate the contents of the view and the size of the screen.
You can get this tool from your Android SDK sdk/tools directory
http://developer.android.com/tools/help/draw9patch.html
Note : I You want to put image according to device resolution add your image to these folders hdpi, xhdpi ,xxhdpi
You can put images in Mipmap of all the resolution in different folder like hdpi, xhdpi ,xxhdpi and you can use it

To have multiple nine-patch images or just one? If one, where to put it?

So far, I always created one nine-patch image and place it inside /res/drawable-hdpi.
But I saw some large projects which have multiple nine-page images, scaled and placed inside multiple res/drawable-xxx directories. Is this the wrong approach? Nine-patch was supposed to stretch across all screens, regardless of its DPI.
Also, if I am right and only one nine-patch is to be used, what is its default location - drawable-hdpi, mdpi, or some other directory inside /res?
Well, it really depends on quality.
If your image is just a square border, it can be a 72 dpi low res image put into the drawable folder and it would be enough.
If your image has rounded corners or other fancy elements that have to be scaled properly, you could make a 480 dpi version and put it in the drawable-xxhdpi folder. This will scale down (don't even think of scaling up, because of stretching/pixellating) good enough in most cases.
If you want the best quality in scaling, then make a version for each dpi drawable folder.
If you go to http://developer.android.com/guide/topics/resources/drawable-resource.html, you can see it there (citation):
file location:
res/drawable/filename.9.png
The filename is used as the resource ID.

Android Development - Resizing images into drawable folders

Is there a way to get Eclipse to automatically re-size images and put them in the appropriate drawable folders? When you add an image for the icon when you first create an Android project, it automatically re-sizes the icon and puts them in the appropriate folders. I know you're meant to scale images using a 3:4:6:8 scaling ratio (http://developer.android.com/guide/practices/screens_support.html). I'm wondering if there is a way that Eclipse does this automatically for images?
For re-size icons, right click select New/Other… or press Ctrl+N, select Android Icon Set, the default name for icons is ic_launcher, click Next, in Foreground select Image and Browser that image like to put as icon and is re-sized automatically
Is there a way to get Eclipse to automatically re-size images and put
them in the appropriate drawable folders?
NO, until now, you have to create your own resources defined for every "Screen Density", tools like android_img_resizer will work but can´t support all densities, what if you need resources with mhdpi or tvdpi density.
More info:
Supporting Multiple Screens - Using configuration qualifiers
Designing alternative layouts and drawables
Supporting Different Densities
For re-sizing the images in bulk i will recommend you this tool https://github.com/bearstouch/android_img_resizer . its easy to install and it support the new resolutions (xxxhdpi,xxhdpi) as the base image.Check it out.

Categories

Resources