I see a lot of post on this topic, however I haven't seen an explanation on what image size to take as a reference, let me explain.
I want to add a background image and make it suitable for each phone screen size so from mdpi to xxhdpi (if I'm not talking nonsense)
What size should my base image be?
I used a 600x1200 image and a 1080x1920 then converts using this site
https://romannurik.github.io/AndroidAssetStudio/
Unfortunately I noticed that on my two phones the image was distorted, I'm starting to think my base image size was wrong
So my question
What image size should I take to then create multiple densities ?
Sorry if it's redundant !!!
I'm starting to learn how to adapt and it's not that easy
If you want to create a background picture, your reference size is mdpi with 320x480px. You can then calculate the size according to the factor
hdpi: 1.5 (480x720)
xhdpi: 2.0 (640x960)
xxhdpi: 3.0 (960x1440)
xxxhdpi: 4.0 (1280x1920)
Note however, that nowadays devices have all kinds of other aspect ratios (mostly longer). So you have to design your background in a way, that the outer area does not contain important content. Then use ScaleType CENTER_CROP and your image should not be distorted (https://developer.android.com/reference/android/widget/ImageView.ScaleType)
I think the site is for (mainly launcher) icons.
If your target device's display has 1080x1920 size with xxhdpi (3x) density, just put an image of the size in the res/drawables/xxhdpi folder. No other densities are needed to be prepared. They will be re-scaled from the xxhdpi image if needed.
If you still want to prepare for those densities, first prepare the highest density. If you want to use xxxhdpi (4x), you should start with xxxhdpi sized image. Then scale it down to xxhdpi (3x), xhdpi (2x), hdpi (1.5x) and mdpi (1x).
xxxhdpi (4x): 100%
xxhdpi (3x): 75%
xhdpi (2x): 50%
hdpi (1.5x): 37.5%
mdpi (1x): 25%
Support different pixel densities: Provide alternative bitmaps
Related
I did some research and found that there 6 different sizes required by Android to display images properly on all sorts of devices.
LDPI - 0.75x
MDPI - Original size
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
So suppose I have 100x100 image as a baseline (MDPI), then ldpi, hdpi, xhdpi, xxhdpi will be as follows.
LDPI - 75x75
HDPI - 150x150
XHDPI - 200x200
XXHDPI - 300x300
XXXHDPI - 400x400
But I have confusion as to what should be the baseline(mdpi). How do I select my baseline, does it have to be based on something? I can have different images in my app example a back arrow, home arrow, a background image(full screen), an Add icon and so on. But all these icons have to different sizes. So how can I choose my baseline size?
No need to choose, the mdpi(baseline) density means that one dp is roughly equal to one pixel. So we call it the baseline density.
If we provide icon with size by the definition. We will get all the icon image have same physical size on different density screen(ldpi,mdpi,xdpi and so on) with proper quality.
About the background image, I would recommend to put the background image to drawable-nodpi which the image just fill entire screen no matter the density, so just put it there to let the system don`t scale the image and save some memory resources to scale it.
reference Support different pixel densities
Check if this can help you,
Material design icons
I am creating an app with an full screen background image. I read a lot and made different images for different resolutions with the recommended pixel size and provide it in different drawable folders:
xxxhdpi: 1440x2560 px
xxhdpi: 1080x1920 px
xhdpi: 768*1280 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px
I tested it on different phones and all look great.
Now my Problem: it doesnt't look great on tablets... and its logical. Samsung Galaxy tab 10 for example is 800*1280 mdpi.
So what is the solution? different folders for phones and tablets (7" and 10")? are there recommended sizes in pixels like there are for phones? how do others do this?
Thanks a lot for your advice!
If you are using drawables for background, and the image you added in the drawable surpass the dimensions from the list you supplied, it will be scaled by default (afaik).
Some things you have to keep in mind :
1) This applies both landscape and portrait.
2) If you are downloading the images from the web for creating the background drawable via code, you can handle the desired size by processing that image directly from the backend. Also, with libraries like Glide or Picasso, you can manage the resize thing.
Best regards,
I'm making an android App that shows images at full screen.
I learned some about dpi and dp, but I didn't find how many pixel must be the largest side of my images (in prospective to good fit also in landscape mode) to appear good in different devices.
As in the documentation, the most used screen configurations are normal with hdpi, xhdpi and xxhdpi density:
So, if my thinking is correct, I can make only one image to fit the xxhdpi to works fine also with the other two densities, and put it in Android Studio under the "res/drawable" folder (without qualifier).
Specifying the image size in dp in the layout, Android should scale the image for the smaller configurations.
But, for the xxhdpi, how many pixel must be the largest side of my image, in pixel, to show good?
Edit: how many pixel must be the longest side of my image to be showed properly in a device with xxhdpi density without the image appearing grainy?
All images are photo, not icons, so I can't use the vector graphics.
By looking at the Android Documentation. One can estimate the size of the picture. look at below picture
So, your image resolution should be in similar resolution
LDPI: 200 X 320px
MDPI: 320 X 480px
HDPI: 480 X 800px
XHDPI: 720 X 1280px
XXHDPI: 960 X 1600px
XXXHDPI: 1440 x 2560px
A little bit of +/- won't affect the outcome because with these standard sizes the aspect ratio of any portrait picture should be respected.
Well, if you put the image which fits the xxxhdpi inside the folder drawable, then it will fit all the screens.
But there is another way to use only one image instead of using multiple images for different resolutions. It's by using svg images which are vector images that will not be affected by zoom in or zoom out.
To use svg you need to follow these instructions:
Make the icon to be icon.svg
In the Android Studio, right click on drawable folder
Choose New -> Vector Asset
Choose Local File (SVG, PSD)
Choose your svg file
Click Next and choose the name
Click Finish
In the app build.gradle add the following inside android block:
vectorDrawables {
useSupportLibrary true
}
In the xml layout file, add the following:
<AppCompatImageView
android:width="wrap_content"
android:height="wrap_content"
app:srcCompat="#drawable/your_svg_file"
/>
Android have ratios defined for a image to set in all different drawables
Android icons require five separate sizes for different screen pixel densities. Icons for lower resolution are created automatically from the baseline.
mdpi: 160 dpi 1×
hdpi: 240 dpi 1.5×
xhdpi: 320 dpi 2×
xxhdpi: 480 dpi 3×
xxxhdpi:640 dpi 4×
Above size is for normal pixel icons. There are fix android size for Action bar, Dialog & Tab icons, Launcher icons & Notification icons
Check this link for more details http://iconhandbook.co.uk/reference/chart/android/
You have to take a look at the current market of smartphones.
Here you can see the screen sizes and resolutions of the most popular devices in the market.
http://screensiz.es/
Order the list in pixel per inch and you will see that top smartphones have resolutions bigger than 500 ppi or another way to see it, much bigger than 72ppi of your images.
If you have enough space to store or mechanism to download images try to test with full quality. If thats too much try to find a compromise. Lower image quality and see the result in high resolution screen.
Note that you didn't posted here the total size of image, in case is bigger than screen size, take a look at total size of image and compress it to fit your needs, maintaining as much as possible the resolution.
Edit: Looking only to size of image in pixels, the current biggest screen in smartphone is 2560 x 1440 pixels, so you wont need any image bigger than this.
If I understand your answer correctly, you are talking about images (pictures of lovely cats and dogs?) and not about icons?
I prefer putting images into the nodpi folder.
nodpi Resources for all densities. These are density-independent
resources. The system does not scale resources tagged with this
qualifier, regardless of the current screen's density.
Afterwards I would create a fullscreen ImageView and let imageView do the scaling if needed
The Galaxy S5 has a display resolution of 1920 x 1080, an iphone is 1334 x 750, and many others are similar. Do these resolutions work the same way that Apple's retina screens work, where images will look blurry unless they have an #2x size version?
Basically, if I am creating a mobile landing page for an add, and I use an image that is 300px wide in the browser, will that image look sharp like it does in the browser or do I need to do something else to make sure it looks good on mobile devices?
If you're talking about photos or photo-like images, Android resizes those fairly well and does a fair job of avoiding unpleasant image artifacts because it uses very accurate rescaling methods.
Anything you expect to be "pixel-perfect" like a 2px-wide line in the image is simply always to be somewhat blurry in a resized result. For those types of images, you'd want to generate different resolution versions of the images in the drawables-* (or mipmap-*) folders and keep in mind the relationship between screen density and pixels.
MDPI is 1:1
HDPI is 1.5:1
XHDPI is 2:1
XXHDPI is 3:1
XXXHDPI is 4:1 (and something you're unlikely to find right now)
...so if you wanted a 1px border in an image that's to be displayed on an XXHDPI screen, in the drawable file that line would need to be 3px wide. The good news is that since these downscale and upscale quite accurately, under most circumstances, an image from drawables-xxhdpi will retain a perfectly clean edge when downsized to all the others (except HDPI, because 1.5) and an image from drawables-mdpi will upscale decently as well. Android will do the best it can at picking an appropriate image to upscale/downscale from the drawables/mipmaps folders when some are missing (i.e., you might not need to populate all of them).
Android's support for higher resolution screens is based on screen density.
A set of six generalized densities:
- ldpi (low) ~120dpi
- mdpi (medium) ~160dpi
- hdpi (high) ~240dpi
- xhdpi (extra-high) ~320dpi
- xxhdpi (extra-extra-high) ~480dpi
- xxxhdpi (extra-extra-extra-high) ~640dpi
http://developer.android.com/guide/practices/screens_support.html
You need to create additional drawable folders and place your higher resolution images there. drawables-hdpi, drawables-xhdpi, drawables-xxhdpi, etc...
There are some tools that will help you resize images to the various densities too. Like this one: https://github.com/redwarp/9-Patch-Resizer
I've read 10 articles yet still cant find any relation between ldpi, mdpi, hdpi and the actual dimensions in pixels!? Can anybody give a straightforward answer please(if there is one!)
I'm basically trying to put together a splash screen that needs to work on multiple devices without stretching - but i'm struggling as everything I try is either squashed or stretched!?
Cheers
Paul
The ldpi, mdpi and hdpi refer to screen density, which means how much pixels can fit into a single inch.
the ratio in pixels between them is:
ldpi = 1:0.75
mdpi = 1:1
hdpi = 1:1.5
xhdpi = 1:2
xxhdpi = 1:3
xxxhdpi = 1:4
so lets take an image with about the size of 100X100:
for mdpi it should be 100X100
for ldpi it should be 75X75
for hdpi it should be 150X150
for xhdpi it should be 200X200
for xxhdpi it should be 300X300
for xxxhdpi it should be 400X400
this way, for screens with the same size but different DPI, all the images seem the same size on screen.
Also you have multiple screen size types small, normal, large, xlarge and each one of them can be ldpi, mdpi, hdpi, xhdpi, xxhdpi (Nexus 10) or xxxhdpi.
You can try to create a splash screen image that fit to each and every screen type
which gives you 4*5 = 20 different images (it seems to much for me).
For now only the Nexus 10 is at the xxhdpi category.
Install ImageMagick and use this shell script to generate your splash and icon files for multiple devices - iOS, Android, Bada and Windows Phone. You can use cygwin/gitbash if you are on Windows
I just did and I'm pretty happy with it :-)
The screen sizes are inside the script and are -
480x800 - screen-hdpi-portrait.png
320x200 - screen-ldpi-landscape.png
720x1280 - screen-xhdpi-portrait.png
320x480 - screen-mdpi-portrait.png
480x320 - screen-mdpi-landscape.png
200x320 - screen-ldpi-portrait.png
800x480 - screen-hdpi-landscape.png
The definitions are:
xlarge screens are at least 960dp x 720dp. large screens are at
least 640dp x 480dp. normal screens are at least 470dp x 320dp.
small screens are at least 426dp x 320dp. (Android does not currently
support screens smaller than this.)
Also, check out this blogpost from Dianne Hackborne:
http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html
Probably the easiest thing is to use an image view and set the scaletype to CENTER_CROP.
(Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view).
Make sure that you use the src tag rather than setting the background.
<ImageView
android:id="#+id/home_video_layout"
android:src="#drawable/splash_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
/>
Updated:
Understanding Screen Densities and the “dp”
Resolution is the actual number of pixels available in the display, density is how many pixels appear within a constant area of the display, and size is the amount of physical space available for displaying your interface. These are interrelated: increase the resolution and density together, and size stays about the same. This is why the 320x480 screen on a G1 and 480x800 screen on a Droid are both the same screen size: the 480x800 screen has more pixels, but it is also higher density.
To remove the size/density calculations from the picture, the Android framework works wherever possible in terms of "dp" units, which are corrected for density. In medium-density ("mdpi") screens, which correspond to the original Android phones, physical pixels are identical to dp's; the devices’ dimensions are 320x480 in either scale. A more recent phone might have physical-pixel dimensions of 480x800 but be a high-density device. The conversion factor from hdpi to mdpi in this case is 1.5, so for a developer's purposes, the device is 320x533 in dp's.
I have found this online dip <--> pixels calculator very useful.
https://pixplicity.com/dp-px-converter/
I support previous answers but don't forget the power of Draw9Patch or using NinePatchDrawables
These refer to screen pixel density, not screen dimension. You need to look into screen size specifiers like small, medium, large, and xlarge instead if you really need to change behavior based on screen size in pixels.
The Android docs explain what densities and sizes match these identifiers.
Android devices can have different width-to-height ratios, while your image has a fixed one. If you do not want your image stretched, you will have to fill the blank spaces above and below or left and right.