java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at nis.animation_door.Page5.onCreate(Page5.java:32)
Basically it tries to rescale/resize background images i m using.
the images have 1024x768 size
I use SonyXperia tablet z(real display size - 1920x1128px)
Following similar question answered on SO I have put all background images into drawable-hdpi,ldpi etc folders
At runtime, Android resize's images based on need (based on the screen size and resolution). It uses Bitmap's for doing the resizing internally. Which, obviously, is very memory intensive (kinda allocates memory like crazy). One quick way to fix such issues can be, that you copy all drawable files to drawable-ldpi, mdpi, hdpi folders. This way android will just pick up the files from these folders and not resize them.
This did not help, I suspect because even if you put same images into ldpi folder, you have to resize/rescale them manually.
My question - if make my bkg images exactly same size as my real device - 1920x1128, will it help? any other suggestions?
Related
I had different nine-patch images for different screens. However, I encountered an issue
android drawable image takes lot of memory compared to its disk size
So, I decided to use, for now, nodpi with hdpi image size.
Since, I have limited understanding, I was wondering what should be the image size I should put in drawable-nodpi folder.
Should I put hdpi images or xxxhdpi images? Or something else?
Please help me understand.
I'm programming for a little game in android, but i'm stuck at understanding how the scaling of drawables work or should be done.
I'm drawing a Tilemap in a View on a Canvas with Canvas.drawBitmap()
Main problem is that i don't know how i should manage bitmaps to occupy the same space independent of screen resolution.
My Tile is 64x64 png file and it's placed in drawables folder. Then if i want it to occupy the same space in a xxhdpi screen what should i do?
Should i place in drawables-xxhdpi folder the same tile but as a 192x192 file? Or should i convert px to dps for the drawBitmap() method? Or is there something else?
I'm getting really confused trying out things, and i see myself not getting anywhere.
Thanks in advance!
You're right. You should keep a bitmap file with different resolutions in different drawables folder. That allows the application to fetch the required files automatically on the basis of the size of device the user uses.
I have a set of 4 images I plan to display at the first launch of my app inside of a ViewPager. Each of them is 1MB, so that's 4MB total
I want these images to be shown for any density screen.
Where should I place these images?
In which size?
Will duplication increase the size of my app?
Maybe a more efficient way to do it? (one location for these drawables)
The closest I've found is http://romannurik.github.io/AndroidAssetStudio/ but it's only for icons
Thanks!
Q1.2. Location: /res/drawable. You can have many version of those images and place them in different folder: drawable-hdpi, drawable-ldpi... For better result, please read http://developer.android.com/guide/practices/screens_support.html
Q3. Duplication will definitely increase the size of your app. But common users will possibly ignore its size is not ridiculously big.
Q4. You can store only one image for every screen size, but you need more coding work to scale the drawable to fit the screen of different device. For better result please read: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
I have a beginner question in android. I wanna create a backgammon game. I found images of board online and converted it to different dpi using online tools. Now when I decode it using decodeResource and display it in canvas it's very small. and when I scale it it has very bad quality.I tried all solutions including using matrix for scaling and different paint options. I think the problem is with the image itself. it's 72*72 by default. should I make it larger and then put it into dpi folders?
thanks in advance.
72*72 is very small. You should better make an image in 1920*1080 and put it into the drawable folder so it's not depneding on the size of the screen. You can always scale it down. Maybe make a smaller picture and put it in drawable-small to save ram on smaller devices, since bitmaps are pretty large.
I am wondering what your thoughts are on which is the better strategy when designing UI for android devices.
Which do you preffer:
Setting the size of elements in the XML files, for each denisty (and size when needed), using only one set of images (xxhdpi images) which will scale down when needed.
Pros - smaller apps (less resources)
Less work on images for UI people.
Cons - more work on XML files (a whole lot sometimes)
Create images for each denisty (and size if neede) using Wrap_content most of the time.
Pros - Only one set of XML layout files.
Cons - more images and larger sized apk.
more work on images for UI people.
What other approaches are you using?
Thanks!
I think you are misunderstanding what Android is doing when it scales images that you do not provide. The Android docs state:
By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities.
All this means is that if you do not provide alternate density versions of images, Android will fill in the missing ones (created and the correct proportional size) using the ones you have provided, but at the cost of some quality of the image, since Android is not going to scale an image as well as say Photoshop. If you are concerned with application size, you can consider if the loss of image quality from omitting certain density versions is an acceptable tradeoff in order to make your .apk smaller.
So, #1 and #2 can both use wrap_content, and neither has to set the size of an image manually, unless the image needs to be larger or smaller than the original size (which in that case you should just create the image at the right size). #1 also does not and should not require more layout work. And for #2, saving an image at several sizes is not very much extra work at all.
I personally follow these rules:
Create images for every density (except ldpi / tvdpi - too few devices, I'm ok with the image quality loss on them).
Use wrap_content and match_parent as needed with images.
Only use dp for images downloaded at runtime, where size cannot be guaranteed.
my choice is a mixed one. I create differet images for those which are complex and has a chance of being abnormal for automatic compression. But for usual images I only used the first approach.