I'm new to creating animations on android.
I'm trying to create a large frame by frame animation using a lot of .png's.
I have two animations I need to play, with one of them being 100 frames big and another being 40.
I am currently using AnimationDrawable to create the animations however I am getting a
"bitmap size exceeds VM budget" on any device with less than 1GB of ram (anything over that and it runs fine).
The 100 frame long animation is created with 78*334 sized images
And the 40 frame animation is created with varying image sizes from 320*290 and 320*309.
I also need to be able to reverse the animations at random times (currently I just create another animation as necessary with the frames in reverse from the current frame and it works perfectly)
So I soppose my question is how can I create multiple frame by frame animations with lots of frames (or the appearance of an animation) without running out of memory on lower end devices.
i had the same problem before, it was too painful to reduce memory usage while declaring an animation list as (in your case) 100frames*78px*334px*4bytes = 10,420,800 bytes if using uncompressed format.
i used video instead of image sequnce i could use more video frames and resolution (in my case) 5sec*25fps*480px*854px on the the H.264 mp4 codec and it works like a charm :) no delay no overhead on sonxy xperia u 256mb of ram
you can create multiple frame by frame animations in the android but only make sure your
images(PNG)resolution is small...I have done this in my project with *320 * 480* resolution..its works perfect..but just one problem in that ,There is a loading time when you first start the animation depending upon your number of images...
Related
In animation drawable, you can load up an animation list that has multiple frames that would play one after the other. I am just wondering about memory consumption/efficiency here . If I have 50 or 60 images, does that mean they are all loaded in memory and then rendered one by one, or is it loaded one by one and replacing the older one?
Any idea how this works?
Thanks
Yes, AnimationDrawable loads all of the frames into memory at once. You can read more on this here - link
I am stuck showing frame animation in android. My problem is that I have to animate 36 images. The smallest image is 69 kb in size and the biggest(last frame) is 526kb. A total of 11mb. I know its insane but I need to do it. See images below. The app is already made for iphone and I have to port it to android.
Requirements:
smooth animation
no frame loss
consistent with iphone
The solutions I tried are:
AnimationDrawable by providing in xml files. Problems: the start time is almost 6 -12 seconds. Images lose frames so jaggy experience.
Change imageview bitmap inside a handler. Problems: Frame loss and Out of memory
Create a custom imageview class. Define a method showAnimation() and inside it update bitmap and invalidate() the view unitl the last frame. Problems: Not fitting my requirement. This by far gave the best result but not half as required.
I am a noob in opengl and gamedevelopment. I am unable to find any alternative to my problem. Please help.
Smallest image:
Last image:
I can visualize the effect you are aiming at.I guess doing this will require pushing in different images onto the same imageView, with incremental frame rate.|
The accuracy will depend on the number of images you have. Greater the number of images finer will be the precision.
Also you need to implement incremental frame rate. So that it gives a smoother feel.
Doing this should be possible using a simple loop to change the image resource of the imageView Controller. There must be lag between two iterations, this lag will actually be the frame rate.
I think this can give satisfactory results.
Going for openGL, however, you will not need all these images. It will just require one image of the card that will be animated and duplicated to create the final image. This however is a complex piece of task(I think) so if you are catching some dead lines, you must go for a non-openGL solution like the 1st one, I have suggested.
I have a png sequence that I want to display in an imageview. It has 745 frames of up to 44kb each and want to play it at 23 fps. Some of the frames have are different from the previous frame or are blank so I could skip updating on frames 100-243 and 340-400 for example. So the total size on disk ends up around 9mb (I only use need to use 249 images out of the 745 frames beacuase there are some pauses in the animation and some times the animation object goes off screen). All images are 320 x 480 and are scaled to fit the screen.
While it's playing I need to do some other stuff along the way without stopping the animation.
I'm new to Java. In pseudocode I would like to do something like this :
The Activity loads...
For x = 1 to 745
if exsists("image" & x) then
imageview setbackground("image" & x) (change this every 35ms)
switch (x)
case: 10 then call a function at frame 10
case: 100 then call a function that vibrates 0.5sec at frame 100
case: 200 then call different function at frame 200
Loop
End the animation...
Then close the Activty.
So the question is how to do this on the Android?
I tried using an AnimationDrawable and an animationlist.xml array but get a Simulator VM Error if I have more than 40 frames.
I can get a little bit more to run on the actual device.
Any help to point me in the right direction would be apprieciated.
I ended up finding the solution I was looking for the Timed Loop although it does bring up a new issue regarding my frame rate requirements which I have included in a new question.
If you only need to update images every 70ms then this solution seems to work without the same memory restrictions as AnimationDrawable.
See new question at:
750 frame transparent PNG animation in ImageView at 23fps
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.
We are building a scrollable background, and currently have one large background image that we split up into 512x512 tiles, and want to load these tiles as they are needed, instead of all at once, when calling GLUtils.texImage2D within onDrawFrame, we have noticeable lag we think because of having to load the texture onto the hardware, is there a better way to do this?
Thanks.
Use texSubImage2D() to reload existing texture objects instead of creating entirely new ones.
G'day buddy,
I think the sheer amount of image data you're trying to transfer within a frame time is a tad much: if you are using a 24bpp format, 512x512 amounts to 1 MB of data. I can think of two ways to minimize it:
Change to a bitmap format that has less bpp. If you are using ARGB8888 you might want to try switching to RGB565 (as it is a background) to halve the data.
Consider splitting up the 512x512 into e.g. 4 chunks of 512x128 (since you are scrolling vertically). This way you distribute the loading over more frame intervals.
Cheers, Aert.