I'm developing the splash screen for an Android application and I wanted to simply put an image designed in Photoshop as a background. The problem is that when I save the image its resolution is 1080 x 1920, but when I add it as a drawable in Android Studio, it gives me the error "Bitmap too large..." and says that the resolution is 3240 x 5760 (exactly 3 times bigger). I can't figure out why this happens, can you please help me?
Thanks
drawable folder in Android actually represents drawable-mdpi folder.
If you put images in drawable folder they will be upscaled in devices with higher dpi. That is why you are getting larger image.
Put your image in drawable-nodpi folder to prevent automatic up or down scaling of images.
you can also use this http://nsimage.brosteins.com/ link.
Go to Upload an image and a zip file will be downloaded containing 6 drawable files.
Extract files and copy those 6 folders in : \app\src\main\res.
Related
I want to have an image show up in my Android application, but it always comes out blurry. What do I do? My image is 10000x11866 pixels, and I've made it big on purpose so that it wouldn't come out blurry, but it still does.
Here's my approach: right click the 'res' folder -> new image asset -> set icon type to 'action bar and tab icons'
What am I doing wrong?
Action bar and tab icons are much smaller than that, so the wizard is scaling down the image. Do not use the Image Asset Wizard for your image.
Instead, create a drawable-nodpi directory under your existing res directory in your module's main source set. Then, copy the image into that drawable-nodpi directory.
Note that you may run out of memory with an image that size, and there is no Android device with a screen resolution anywhere near that. I recommend that you reduce the resolution to something more reasonable, such as 1000x1186.
You can just copy the image and paste it in the drawable folder. Make sure the name of the image is in lowercase.
Also, make the dimensions smaller. There is no need for the picture to have such extreme dimensions. Especially if the image is not being zoomed. 1920 x 1080 1000 x 1000 are big enough trust me.
Post your code so we can see what's going on.
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.
I got a new requirement to present an image instead of an error text if there is no items to show and the image almost have 440 KB (PNG) in size that given by my UI/UX designer. So I don't think it's fair to use it straightforward. As it's a transparent background image it's not possible to reduce the size by converting into JPG format. I got 4 resolutions of the image for placing it in different resolution resource folder. but if I keep all of them in my APK, that itself take near 1 MB, So I had taken only one image from drawable-xhdpi folder and kept in drawable-nodpi. Okay, So my queries as follows
1) How can I efficiently use that image ?
2) Any worries if I use JPG icons as substitute of PNG ?
3) What about keeping images like these only in drawable-nodpi and setting size in different dimension file ?
1) Convert the PNG to WebP if you only need to support API level 13+, otherwise use ZopfliPNG to optimize your PNG.
2) JPG does not support alpha channel and it's lossy.
3) Just put it in drawable-xhdpi and let Android scale the image for you. Only put images in drawable-nodpi if you don't want the image to be scaled.
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
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