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
Related
I am using a button with a png background for CopyToClipboard function in my app (used about 6-7 times in various fragment). Since the image should be small for my purpose, I increased the area of my image by putting in extra transparent area around the image so that I could increase the button size for clickable area but keep the image small (I know its not efficient and since then I have devised better way to achieve this).
I noticed the huge spikes later on afterwards when uploading some other images (big images about 150kb size), and after a lot of debugging (and I do mean a lot!) I found that the problem was not due to the bigger images but due to the CopyToClipboard image which was of just 8kb in size!!! Changing back to older CopyToClipboard image (having lesser Transparent area) brought the memory consumption back to normal.
My question is why did that happen? For such a small image to create such huge spikes (more than doubled the memory consumption from previous) and made the app slow, is quite baffling.
Image shown below : The White area is the transparent area. My button dimension : 15dp x 15dp .
I repeat, My question is why did that happen? Not a solution for it since I already solved the problem.
It doesn't really matter that your image is only 7-8KB on disk, because it will take much more memory when it's decoded.
Apparently, large transparent area can be efficiently encoded in PNG file, so the image has that small size.
But in fact, it's dimension is (600 x 745), so in memory it will take roughly (600 * 745 * 4) bytes, plus some meta information, so nearly 2 megabytes. 4 multiplier stands for an amount of bytes needed to encode color with alpha channel.
Android Bitmaps are represented internally by linear one-dimensional array of integers, so you can imagine that system needs to allocate an array with size 600 * 745 = 447000 to create your Bitmap.
That's why memory consumption is so high for such a simple image.
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'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...
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.
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.