I'm developing an app and I got several HD Images (PNG Files) throughout the app. To navigate through the app as quickly as possible, I want to load all pictures in RAM and display them when the certain activity starts.
Means each activity has a HD picture.
Since it is quite impossible to load a 32bit HD Image to the RAM of the app, I had to resize them using that bitmap shit of Android. But I don't want to resize them.
Is it possible to load all HD images at the beginning of the app to the RAM? I don't understand why there are HD 3D games like Modern Combat 5 have no problems with that and just take the amount of RAM they need and I can't even load 7 or 8 HD Images at once to my app. Is there a trick? How can I get a Heap large enough for all my stuff to load at once and keep it in RAM while the app is active?
Thank you in advance
You need to recycle() your bitmaps after you complete the work with bitmap, so that will clear your memory :). Read this Displaying Bitmaps Efficiently
Related
Hi There:) I am trying to create Image Gallery in Android, I am trying to load Thumbnails from HD images(more than 1000) from local device.
Glide.with(context)
.load(Uri.fromFile(new File(MyPhotoList.get(position).getPath()))).override(110,110)/*.thumbnail(0.1f)*/
.placeholder(R.color.colorAccent).into(holder.image);
But on scroll, RecycleView stucks and load image after few sec.(CPU: 70-80%, 180 MB, It consumes.)
(Test Device config. Deca-core 2.3 GHz, 4 Gb RAM).
Could you please suggest me, how to make smooth scrolling for image gallery.
I think this is normal behavior. On every another app launch (after the first one) glide will load those photos from its cache so it will be much smoothier.
To explain this just calculate, the phone needs to load e.g 20 photos those size together is about ~200/300 MB. Now take device's flash memory read speed. Most of devices may have about speed rate up to ~120 mb/s, so it means it may load those photos in few seconds.
Take a quick try with stock Gallery app on your phone. Open this and swipe down and see images and videos loading and compare with your app speed. Then you will know how big is difference againist those apps if any.
Im developing an App and the assets used are for the highest resolution screens available so smaller devices have a hard time rendering such big images besides it uses alot of unnecesary memory. So what i want to do is: When you start the App for the first time it will go through all assets resizing them to the size that will always be used on that device so the rendering time will be much shorter and memory use will be lower.
Is there a way to do this?
I'm making an app for android. I use images as screen background.
Time of setting 1848x1080 jpg in imageView is about 65-80ms on my phone. File size is 900kb.
When I reduce image's quality and size (1369x800), the size of file is about 150kb.
But time of loading that image is about 55-60ms! Not much of a difference.
Why is that? Can anyone help me with this - how to prepare images well to be loaded as quickly as possible in android and still look well on Full HD screen?
That is because Android as an operating system has to create an internal file descriptor in each case. That takes always the same time, so you don't win anything if the file size changes.
I would recommend you to preload the files you quickly need and hold them in the memory (caching). This will maybe blow up the memory used by your app, but it will allow you to display those images really fast.
Hoping someone can help me solve this.
Im making a very simple game on android 4.2.2 using just UI elements, ie no 3D, opengl, Just as a challenge really but I've ran into a little head ache.
I was having O.O.M issues with loading graphics (to be expected with android) so i looked for other routes and found bitmap factory and decided to use a simple implementation. with my images i was hitting up to 40mb allocated memory during game play so I reduced the files from 1080x1920x4bit to 540x960x4bit in a hope to reduce memory load but now it reaches up to 72mb during game play.
Am i missing something or is me thinking, halve the size of images and halve the memory usage? or does upscaling use that much more?
is there any way I can reduce this amount of memory down to a decent 16-20mb range?
Notes on the APP.
all images are stored in res/no-dp or res/xxdpi. And are all jpegs.
I have six pop up images which are 100x100dp jpegs and 5 x Life segments which are 50x50dp
this is the code im using to load the images from bitmap factory
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.dummy1nn);
button7.setImageBitmap(bMap);
and im loading the other images as background resources for now via buttons or image views.
I also have soundpool running on elements and a timer.
Any help would be appreciated. I dont want to post all my code as it is a right mess at the minute as im trying many different methods to get this working smoothly. The only issue i have is the memory load.
My current memory after running the game and letting it sit for 5 minutes is:-
Heap size - 73.086mb
allocated - 70.40mb
free - 2.625mb
used - 96.41%
objects - 47,161
I'm using LG Nexus 5 'hammerhead' as DEV device with unlocked bootloader and stock rom.
Thanks guys. :)
edit:
Answer was to use picasso, although there are a few image libraries out there i liked the simplicity of picasso a lot. and always use MAT when using images to make the relevant changes to quality/size and format to get the lowest memory print (mine dropped to 26mb peak)
have fun
Picasso is a really good library that will handle memory management, asynchronous loading, and caching for you.
Using your example, it would be used simply like this:
Picasso.with(this).load(R.drawable.dummy1nn).fit().into(button7);
I have an app which takes photo and then process it in NDK. The image processing is really havy and i want to take different resolution images on different phones. So my simple logic is taking higher resolution image for powerfull images and taking lower res. images on low end devices. There are three criteria first two are memory and cpu, if i take a full res image on low end phone like galaxy s it will crash during the image processing because of lack of memory. And it will take forever to process image. Third one is camera picture sizes. So here is my question, how can i profile a device and decide for the resolution of the image?
PS: I am doing image processing with OPENCV so GPU is not an option.
PS2: Since i can't make comments i should clarify that i am not trying to profile my own code i am trying to profile devices that users will use.
I suggest Valgrind. It supports ARM-based and X86 Android for profiling and memory leak detection.