Fullscreen iPhone animation from PNG - iphone

I need in animation of sequence of more PNG files (300 png files and size is 320x480).
I've try make it with 12 fps, but sometime iPhone 3g have lags... 3gs working fine. I think 2g working with lags always.
I've use one UIImageView and loading images in NStimer callback by UIImage:imageWithContentOfFile.
May be this is not best way to animation png files ?
note: previously i've used ImageOptim to pack (or strip ??) all my images (from 20% to 80% of size strip).
regards,

Using an image view for full-screen animation is really not going to go well, regardless of how you compress your images. Make the frames into a video file and use MPMoviePlayerController.

The way that I found is use JPG files it works really faster.
And we do not need PNG if fullscreen animation (tested on iPhone and iPad).

If you can afford some sort of delay when the apps start, you may cache some images (say, storing them in NSMutableArray) before displaying them. This assume the bottleneck is in the imageWithContentOfFile call.
One more option is to keep imaging loading in a NSOperation (thread in its simpler form).

Related

The iPhone Game Background as Video or Animated Image?

I need to create a very short background animation for the entire iPhone screen. I am trying to figure out whether I should use a video or animate a series of PNG files.
Does anybody know the advantage of using video as an app background instead of the series of PNG files being animated inside UIImageView? I heard that video can be compressed to really small size and will look better that animated PNGs.
Thanks in advance.
I really don't think using a video rather than a series of PNG is a good idea. You'll make your life more complicated for a few kilobytes saved, if you even save any.
It is of course highly dependent on what exactly you are trying to animate, and where you try to save space. For example, if you try to save memory in the binary and if you have your PNGs (already well compressed format) in a zip that you unzip on the fly, most similarities will be factored out by the zip algorithm. If you're trying to save space in memory during the game itself (not in the binary), then this doesn't count. However, loading up the video library binaries has a serious chance to clutter your memory more than the few PNGs will.
This project does the job with JPG, it should be very easy to change that with PNG ;)

Loading a 20MB png in a UIImageView embedded in a UIScrollView

I have a large png Image that I need to Zoom&Move.
I therefore created a UIScrollView and embedded a UIImageView.
The App works fine in the simulator, but when running it on the device (8GB iPod Touch) it crashes as soon as the view is loaded.
I tried with a smaller test Image (4MB) works fine and suspect the iPod can't handle a 20MB PNG. I also tried different other formats, such as JPG (in various save patterns), but that did't help either.
Any clues how I can solve this?
Ouch, 20M is a large image. The first thought that comes to mind is can you dice up the image? I.e. instead of one image have a whole bunch of small images which together make up the larger image. Then you can load on demand the same way google maps downloads image squares.
have a look at the ScrollViewSuite Example from apple. Sounds exactly like what you are trying to do.
3_Tiling demonstrates:
How to subclass UIScrollView to add content tiling
Reusing tiles to optimize performance and memory use
Changing the resolution of the content in response to zooming
I suggest the Example Photoscroller. It demonstrates CATiledLayer which you can use to tile your image and even use smaller images as lod images. It's much smaller then the complete ScrollViewSuite example but has everything you need to do what you want. It contains only 2 classes which you should be able to use in your project with minor edits.
You might want to check the WWDC 2010 Session #104 "Desinging Apps with Scroll Views"... they handle and explain that example.
You will need to tile your image. I suggest imagemagick for that :)

Updating saved images for Retina Display

I have an iPhone app that, among other things, allows users to store photos. When a new photo is added to the app's data store, I cache a thumbnail version of the image so that the photo thumbnail grids load in a reasonable amount of time.
The problem is that these thumbnails look great on a pre-Retina Display screen, but they look a little blurry on RD displays. It's not so bad that the images are unusable, but I would really like to be able to get the full benefit of Retina Display for images users saved with older versions of my app.
The problem is that re-creating all these thumbnails takes way too long. In my tests, it took about a minute and a half to re-encode a sample database to high-res thumbnails (admittedly a large one) on my iPhone 4. It will be even worse on older hardware.
How can I get around this? Doing a one-time migration seems out of the question, given the performance results above. Other options are shrinking the thumbnails lazily (i.e. as they're displayed on-screen) and then saving them to the database at that point. Screens full of old images will be sluggish the first time they're viewed, and then snappier after that.
Are there other approaches to consider? Anyone else faced this problem?
I dont like the idea that you try and convert the images.
User will quickly get impatient and say you app is buggy and takes ages to load.
I think you solve the situation without any re-processing of full sized images.
On older hardware you would not have a retina display (so no need to upsize the images). If they have a retina display then they have a fast iPhone iPod.
I would suggest you graphically solve the problem by how you display the thumbnail images. so instead of fullscreen put a border around this image and show it at its true resolution (dont upscale it). Or show 4 images where you normally show 1 (since iPhone screen is 4x the resolution).
Instead of resampling the original massive image, you could do a bicubic upsample of the thumbnail making it 4x the size. This will make it slightly blurry but it should look better than the iPhone scaling which will look really bad. The upsample would be ultra fast as its working with a small image.
I cannot help you out on upsampling but there will be some code somewhere.
Cheers, John.
Screens full of old images will be sluggish the first time they're viewed, and then snappier after that.
It doesn't have to be sluggish.
It's a bit of a pain, but you can do most of your processing in a background thread. Set the thread priority to something low (like 0.1) to avoid making the UI too slow. The easiest way to do this is to set up an NSOperation for each image you need to convert and add them to a NSOperationQueue with maxConcurrentOperationCount=1.
If writes are not atomic, in -applicationDidEnterBackground: or -applicationWillTerminate: (or in something listening for the corresponding notifications notifications), do something like [queue cancelAllOperations]; for (NSOperation * operation in queue) { [operation setThreadPriority:1]; } [queue waitUntilAllOperationsAreFinished];; you get about 10 seconds or so which should be enough for the image conversion to finish writing to disk (and thus avoid half-written files). For added protection, check [operation isCancelled] immediately before the write if it might take longer than 10 seconds. Obviously, in -applicationWillEnterForeground:, you should restart the conversion (remembering that some of the images have already been converted).
Concurrency issues are fun to track down...
(Note that [data writeToFile:path atomically:YES] isn't sufficient — it's likely to leave temporary files lying around if the app is killed during the write. I'd recommend storing thumbnails in Core Data if you can, but that might be out of the question for existing apps.)

packaging sequences of png files in iPhone APP for animations to reduce bundle size

Basically, I have an application that uses a flip-book style animation technique. I am simply cycling through around 1000 320x480 pngs at 12fps, and everything works really well. Except for the fact that 1000 images takes up a ton of disk space. Ideally I'd like to be able to compress these images as a movie file and pull out each frame as I need them, or simply play back a movie with frame by frame precision.
Ideas?

Best Idea to show a movie on iphone app

i creating an application with movie animation , i have a animation some group of insects fly around a lamp ,
so i render my animation as png images [they are about 400 png image frames] and when i want play insects movie on my app ... it seems the iphone running out of memory (i try short animation and works fine) but long animation not ! .
what's your suggestion to play this animation on iphone sdk , i don't know the MPMovieController is a good idea ! because my animation doesn't any background .
Best way is to create normal movie file and play it with standard controller.
If it's unacceptable, you can do something like this. Two threads, one thread loads images from disk, another one shows them per 1/15 (1/30, whatever) of a second. There are several difficulties:
iPhone flash storage speed. It's very limited. So you can do something like 128x128 animation with ease, and fail to do so with full-screen one.
Such flash using drains battery very fast.
Maybe, you can also store some part of your animation in memory (every second frame for example) so you'll have to load less from flash.