Live Wallpaper FPS issue - android

I am developing a live wallpaper, in which basically I am rotating around 80 frames (jpg images) - the image size is around 80KB each (800 x 1200 dimension) - total images folder size is around 6 MB.
The images loop fairly smoothly, but as soon as I scale the images (I am doing this to show images well in smaller screens) - the FPS goes for toss - any idea on how to scale the image effectively ?
I thought of two things initially - but it's not working well for me:
I thought of putting all the scaled images in ArrayList of Bitmap, but it's giving a VM Budget error (tried to do bitmap.recycle() too - but it's giving another error like, trying to use recycle image). Any thought on this would be highly appreciated.
I though of putting scaled images in SD card - but again, don't know why but FPS is getting affected - otherwise this can be the best way where I can detect the size of the phone and can download the images over internet and put it in SD card. But, as I said even this didn't work well.
If anyone can help with either of these approaches, or can point to a better way - that should be awesome.

First of all try to sample down the image then scale it . this will reduce your memory size. Secondly store this image and use that image there after. you can find sampling and scaling of imager over here. Let me know if you need more help.

Related

How prevent Outofmemory Error loading big image?

I have a Scrollview that contains 4 big size images 750x1023, 750x2265, 750x1898, and 750x1112
I load image with Picasso
Picasso.with(getContext()).load(resIds[i]).fit().centerCrop().into(mainImageview.get(i));
But it brings to OutOfMemory error.
It makes to problem:
not all images load
app closing
Its important not to make image smaller - it can make UI uncorrect.
What the way to solve this problem? id need, to post code of program - just say what piece.
Thanks!
After all manipulation, problem is still unsolved.. If i scale images with BitmapFactory, it gives "Bitmap too large to bu uploaded into a texture", what ever size i write. If a scale with picasso, it crops my image What ever i do, app memmory enought for two, three switching pages... I'm exhausted because of this problem ...Help
The issue I believe is with gl max size which is something like 2048x2048 and the error will be cannot apply texture or something to that effect Picasso has a lot of ways to scale images but if you must use the full size image then its possible to cut the image into 4 or more pieces and assemble it like Google maps check this "Bitmap too large to be uploaded into a texture"

40+ ImageButtons on one screen?

For last 10+ hours I try to get a large (40+) amount of images (in ImageButton format) on a single Android screen without out of memory errors. The activity I work on is an image picker for a coloring book app. Images are of various sizes in the range of (500 to 1200)x(500 to 1200), PNGs (if that matters).
I have tried:
Horizontal Scroll View with images added from the code. The result is slow (I do it on UI thread) and consumes large memory space.
Horizontal Scroll View with images added from the code via AsyncThread. The result is fast but still consumes large memory space. I like the user experience of this one the most!
Grid View and List View - both are very choppy (testing on first Nexus 7). Memory usage is better.
What I am considering
View Pager - first results look better than Grid View from performance perspective (I have not completed it to the moment to assess the memory usage but it should be better from what I understand). Yet, I dislike the user experience and prefer a scrollable list of all images.
Conversion of my resources to JPG (will that get rid of Transparency byte?)
Downsizing the images to max 500x500px
None of the solutions seems as good as the Android Photo Gallery app available on all devices. This experience is what I would love to mirror. No idea how this is done though :(
Two questions.
What is the best way to get such thing (40+ Images scrollable on single screen) done? Is it really ViewPager? ScrollView with AsyncTask and well thought images resolution? Something I have not tried yet?
What is the memory limit I should try to keep below? Looking at Android heap size on different phones/devices and OS versions it seems to be 256 MB, is that fair assumption?
Thanks. Have a great weekend!
PS. On iOS all works like charm when I add all the buttons into a scroll view :(
Some basic calculations reveals your problem:
40+ images at 1200x1200 = approx 57MB, the comments are correct you need to subsample (i.e. thumbnail) the images or use a library such as the Universal Image Loader. Converting to JPG doesn't matter. That is a compressed storage format, the memory required to display the pixels remains the same.
There is a Android Developers article on Loading Large Bitmaps Efficiently with sample code. The following steps are covered in more detail in the article Android Bitmap Loading for Efficient Memory Usage.
The basic steps in loading a large bitmap are:
Determine the required size (from a known size or determining the
size of the target View).
Use the BitmapFactory class to get the bitmap’s size (set inJustDecodeBounds in BitmapFactory.Options to true).
Calculate the subsampling value and pass it to the BitmapFactory.Options setting inSampleSize.
Use the BitmapFactory to load a reduced size bitmap.

Load big size image issue in imageview . Bitmap too large to be uploaded into a texture

I have 270 x 2693 pixel image in drawable folder . When i try to set that image in imagview i got Bitmap too large to be uploaded into a texture warning.
Image sets perfectly in android device < 4.0 but not sets > 4.0 device.
Please help me to resolve this issue.
Code
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:contentDescription="#string/name"
android:src="#drawable/hindi" />
Here hindi is a image in drawable folder and its size is 270 x 2693 pixel.
Problem
This problem is usually related either to OpenGL maximum texture size or the Device Memory. The full error you are getting is probably something like
W/OpenGLRenderer(12681): Bitmap too large to be uploaded into a texture (270x2693, max=2048x2048)
Memory is generally the problem with a large scale image but in your case 270x2693 is 727110 pixels. If you are in RGBA, it's 4 bytes per pixel so 727110 * 4 = 2908440 bytes, which is approximately 2,7 megabytes. That should fit on any devices.
Thus, your problem is probably related to OpenGL. What might happen is that the Android device > 4.0 you are testing on detect that your image is too large for OpenGL and resize it for you, while older devices don't.
Edit:
In my case, the problem is that my 640x1136 splash image seems to get rezised automatically to a 1280x2272 image size to fit my device huge screen. Which also triggers the error message you are having.
If you get this error further on, it is related to the dpi that is used to load the image. As you will find on Android reference, device will load image regarding their dpi which can alter the size of image that is loaded in memory.
Solution
You don't have much choice other than detecting the device size to
load the image properly.
See how to load large bitmap in memory.
You can also use different image size for different device dpi which
can be automatically selected from the Drawable folder by Android.
See the How to support screens which tells you how to setup your
folder.
As other stated, use a smaller image or reduce its size.
Related informations
I suggest you have a look there if you need to support multiples screens.
Android also collect data which are updated every 7 days on Screens size among their users.
Also have a look to this interesting answer which points out a good website to understand Image Size in memory.
Finally, if you are already using OpenGL in your app, have a look to this answer which shows how to detect the max OpenGL texture size.
Why not reduce the size of the image? If you don't want to do that, then rather than specify the bitmap in the XML, load it from program code, and scale it to fit the display. See this guide for more information on loading large bitmaps.
try use this code
int[] maxTextureSize = new int[1];
GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
maxTextureSize stores the size limit for decoded image such as 4096x4096, 8192x8192 . Remember to run this piece of code in the MainThread or you will get Zero.

AndEngine Update Thread Works Slowly for Large sprites

I have created sprite with texture size of 2048X1024 and attached to my scene.
Things are going fine but problem is that when i attach any other sprite with scene it takes time to display. Without this larger sprite things are displayed without any note able delay.
As I attache this larger sprite other attachments start getting time to display
I am working on AndEngine
Please help if any one solved this kind of problem
Thanks
I can't figure out why you would need an image of that size on your screen. The problem is that Android limits image sizes to around 1024 x 1024 so AndEngine is most likely swapping out the different images. Without seeing your code or knowing what you are trying to do, there's not much I can suggest. except to break your large image down into images smaller than 1024 x 1024. If you are doing a game and are using the image as a background I'd suggest looking into using a program called "Tiled" and loading it up in AndEndine using its TMXLoader. There is a tutorial on the AndEngine forum for this.

skinning my app consume huge amount of Mb in the native heap (much more that image actual size)

I use a skin in my app,and load something like 1.5 Mb of images at some of the activities.
This shouldn't be a problem.... 1.5 Mb + default of ~6Mb for the app when loaded... however, things are quite different.
each png I load as a drawable in my layout xmls, is being multiplied by at least 10 from its actual size...., I wrote a sample app with nothing except for a black screen, and loaded it once without anything on it and got native-heap of 5.8Mb, and then loaded it with a small png of 25Kb and guess what.... 6.25Mb.
I loaded my application with nothing but the skin, and it started with 14.5Mb!!!!!!!!
so now I am in the middle of doing a bitmap recycle operation after each and every activity change.
Is this a known issue with android?
png files are loaded with much bigger size inside the native-heap?
is there a solution other than my current plan?
Thanks.
PNG files (as well as many other image formats, such as JPEG) are compressed files, pretty much similar to zip-files. When you load them into memory they will be uncompressed
and take more space consequently.
How much depends on the internal image config, the default is ARGB8888, which takes 4 bytes per pixel. So the memory consumption only depends on the image size, not on the filesize on disk (which can get pretty small. For example: A 500x500 px bitmap consisting of one color has a good compression ratio).
Example for a 500x500 px image is 500*500*4 bytes = 0.954 MB, which is almost one megabyte.

Categories

Resources