I have an iphone app that gets jpeg images through wifi at a rate I can control and displayes them using a uiimageview. it seems that the best performance i can get is about 2fps. it lookes like the uiimageview cant handle [uiimageview setimage:image] quickly.
is there a better solution other than using uiimageview that will allow me a betterframe rate?
I understand you need JSon to pass multiple info from your service but clearly re creating your image from a json string consumes both memory and processor time. Use the Json to pass the url of the bytes instead and retrieve the bytes using another get.
I expect you to have a json like { path = "/images/funnryrabbits.jpg", anyProperty: "anyValue" }
Try using the .animationImages property of UIImageView. It takes an array of UIImages and animates them like a flipbook or an animated gif. You can make some cheap but quick animations by putting in a bunch of slides and letting UIImageView do the animation.
I don't know if you can manipulate that array as it's rendering the animation, is the thing.
Related
I am trying to create an animation using a UIImageView with an array if images. It works great, except that I need a different delay between some of the frames. In an animated gif you can set the delay between frames. Every example I see of an animated UIImageView has a fixed delay between images.
Does anyone know how I can set a different delay between frames? Or, is there an example of such?
Maybe UIImageView is not the right thing to use, so if anyone has an alternative please let me know.
I have posted a similiar question in other forums and no one seems to be able to answer this. It seems like it should bo doable, since .gif images have had this forever.
Thanks
It may seem hacky, but:
From UIImageView documentation:
animationImages
An array of UIImage objects to use for an animation.
#property(nonatomic, copy) NSArray *animationImages
Discussion
The array must contain UIImage objects. You may use the same
image object more than once in the array. Setting this property to
a value other than nil hides the image represented by the image
property. The value of this property is nil by default.
So you need to add your UIImage several times to the array for a delay.
UIImageView does not support a different delay between different images. You will have to use multiple UIImageViews and manage the transition between them manually if you want to have different delays between frames.
Another approach would be to use a UIWebView which is sized exactly to fit a .gif image that has the delay settings you want.
You have to use different UIImageView to get this working. Try this application page. Might be helpful for you. Link: http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial
If you would like to try my animation library in your iOS app, it offers a complete solution to this problem. For example, you could take a look at the APNG app, it is a free app in the iTunes store that displays animated APNG files. This app was created using my AVAnimator library which contains APNG and GIF decoding support. The APNG format works just like a GIF in the sense that each frame can have a delay time, you would use existing software to create the APNG in this case. But, it is easier to just encode a new .mvid file (this is a custom video file format) from a series of PNG imags. To create a longer delay, you simply repeat frames that do not change in the input PNG image series. Either approach could be used to create an input movie that could display with a variable amount of time in between specific frames (the overall FPS would be the same, but specific frames can simply repeat so that they do not change for say N frames in a row). You can also implement specific user interactions like starting an animation, pausing on a specific frame, and then starting again from that same frame.
I want to know that Can we get thumbnails from a live camera or video? If yes then how? Please suggest me what is best way to show more then 20 or 30 live cameras in a UITableView. I have customized the UITableViewCell and added a UIWebView to that cell with the loadRequest. But this is much slower and also got unvisitable on table scroll. How I can get out of these problems.
Thanks,
maybe you can get the data stream from the camera, find how to make an image with that stream and then create an NSOperation to load asynchronously each image view in every visible cell.
To make a table view slick you need to use dequeueing of table view cells. You should also keep track of which cells are being displayed, which ones are going to be (when scrolled) and which ones won't be visible any more, to manage the loading/unloading of the thumbnails.
Bare in mind that you should get the original stream, scale it, then store it. Otherwise you will waste memory storing a big picture that is being downscaled to be shown as a thumbnail.
I hope this brings up some ideas. best of luck
I am trying to improve scrolling performance of a UITableView. I am loading the images using imageNamed: and dispatch_async, but scrolling is very good once the images have been loaded into the cells. I would like to fade in the images only if they are not in the system cache to reduce the jarring effect of the images "popping" into view.
Is there a way to know if an image is already in the system cache?
There is no documented way to look inside the UIImage to check such things.
I think the only way to know for sure that the image is available immediately, is to force the UIImage to be loaded. This can be done in the background, by creating the UIImage and accessing it's pixels, using CGImage functions. If you ensure that there is no rescaling needed (i.e. don't put a 3000x2000 image in a 30x20 space) then it should display without a glitch.
First: I've implement a fairly complex scrolling mechanism for images, that allows to scroll over a few hundred thousands (theoretically) in one single scroll view. This is done by preloading small portions upon scrolling, while re-using all UIImageViews. Currently all I do is to assign new created UIImage objects to those re-used UIImageViews.
It might be better if it's possible to also re-use those UIImage objects by passing new image data to them.
Now the problem is, that I am currently using the -imageNamed: method. The documentation says, that it caches the image.
Problems I see in this case with -imageNamed:
As the image gets scrolled out of the preloading range, it's not needed anymore. It would be bad if it tries to cache thousands of images while the user scrolls and scrolls and scrolls.
And if I would find a way to stuff new image data into the UIImage object for re-using it, then what happens with the old image that was cached?
So there is one method left, that seems interesting:
-initWithContentsOfFile:
This does not cache the image. And it doesn't use -autorelease, which is good in this case.
Do you think that in this case it would be better to use -initWithContentsOfFile:?
Only a benchmark can tell you for sure. I'm inclined to think that UIImage image caching is probably extremely efficient, given that it's used virtually everywhere in the OS. That said with the number of images you're displaying, your approach might help.
I'd say YES. You have too much images to keep all of them in cache so you can't use -imageNamed:. If your images are not displayed many times, you will not get lower performance.
I found one link regarding this which comments of imageNamed method http://www.alexcurylo.com/blog/2009/01/13/imagenamed-is-evil/
I'm currently using a UIImageView with an array of images to create a small looping animation sequence with about 20 images in there (at 320x480). Whilst this works okay for 20 - 30 images, any more and the app quits on the iphone. There is nothing else in my test app at the moment so I know it's just down to the animationImages sequence.
Has anyone come across any samples of doing this type of thing through Core Animation to achieve better performance and allow many more images? From what I've read it sounds like its possible to set up a ton of CALayers and put an image in each, and then create the animation by manipulating the layers on and off in sequence. Is this a good way to do it?
Or, alternatively, as I'm basically after the effect of a looping movie, is there a way to use the moviecontroller to achieve the effect without it fading in and out at the start and at the end?
I'd be grateful for any pointers. Many thanks.
This could be a simple memory issue. 20 images (320x480) is about 3 MB of memory, assuming 8bpp (if they're higher color, obviously even more). You might try loading and unloading as needed (though, of course, that'll mean rolling your own animation, rather than using UIImageView).
Sounds like a simple memory issue.
You could load one or two frames at a time, or actually play a movie instead.