imageview empty after going out of app - iphone

I've created some code to display a image in a imageview when the current image is equal to a certain imageview. It works correctly but If I decide to go out of the app and then back in it somehow doesn't see the current image and the comparison doesn't work anymore.
if (imageview25.image == [UIImage imageNamed:#"BLUEBOXPUNT.png"]){
key25.hidden = NO;
}
So this works but when I leave app and come back in it doesn't see that the image is equal to BLUEBOXPUNT.png
Is there a other way to do this or to do something like in Java I would do imageview25.getImage. I think that would work.

Your comparison logic is checking whether two image objects have the same address. This will only work while the image remains in cache. It's likely that a memory warning will cause the same problem you see when switching apps.
If you want to associate images and their file names, I think you'll need to do it yourself, possibly with a dictionary that is keyed to the names.

If you need to show more than one image. An easier way is to use more than one UIImageView, all are the same size and at the same place. But each show a different image. Then you can show the one you need and hide others(or bringSubviewToFront).
If you indeed need to compare two image:
Cocoa Touch - Comparing Images
OpenCV

Related

How to load images with high Res in UIscrollView

Can anybody tell me how to load or set images with high resolutions in UIScrollVIew .
I am getting memory warning and app is getting crashed without any stack trace.
Thank you in advanced.
I was also working on an app which had UIScrollView and had to request for High Resolution Images. The thing is, you should first check the size of the images being downloaded. Lets say, if the image size is more than 10MB, then it would be difficult for your app to survive with such a heavy load.
You can consider the following methodologies.
1.Download your images and compress them.
2.At a particular instance of time, there is no need to populate your Scroll Views array with all the images at once, instead try to have only three images,i.e
1.The current one which is being shown.
2.The previous one.
3.and the image next to the current one.
You can also take help from the link
http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
You should use the concept of lazy loading. As you said you used UIScrollView that's mean you have lot's of images and I guess you show them one by one or two or three at a time. Load only that images which are visible to the user. One more thing you have to maintain that is when user swipe to next image or next branch of images that's mean next image(s) that's are going to visible to the user. At that time before load the new images release all the previously loaded images from memory. I hope it'll solve your problem.
If you are trying to create multiple UIImageView of high resolution image inside UIScrollView, then it will create memory warning and application will crash.
I will suggest you to try reusable UIImageView , like create 3 UIImageView and replace images in it.
Try circular scrollview.link or UICollectionView

AGImagePickerController difficulty

So I'm using the AGImagePickerController in iPad, I successfully save my selected image in NSDocumentDirectory, and load it into an array. The AGImagePickerController is in my UIButton, so when it is clicked the picker shows up. But what my problem is, how to maintain the checkmark on the selected image even when I go to another viewcontroller. Thankyou.
I think you have to maintain a dictionary or a hash-map for the images which is marked or unmarked separately.
And when your pop up appears you have to redraw all the check-marks which are marked and unmarked corresponding to the NSDictionary images which are present their as a key.
I have also used same type of technique in one of my project.
I hope this works for you and in case if you want code snippet, please let me know.
There is no support for this, yet, but I can add it in a matter of time.

UIImageView Animation delay between frames?

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.

iphone best practice, how to load multiple high quality images

I have about 20-ish high quality images (~3840x5800 px) that I need to load in a simple gallery type app. The user clicks a button and the next image is loaded into the UIImageView.
I currently use [UIImage imageWithContentsOfFile:] which takes about 6 seconds to load each image in the simulator :(
if I use [UIImage imageNamed:] it takes even longer to load but caches the images which means its quicker if the user wishes to see the same images again. But it may cause memory problems later with all that caching crashing my app.
I want to know whats the best practice for loading these? I'm experimenting with reducing image file size as much as is possible but I really need them to be high quality image for the purpose of the app (zoomable, etc.).
Thanks for any advice
[EDIT]
Hey again guys,
Thanks for all ye're advice. The project's spec's have changed a little. Now as well as displaying the images they firstly have to be zoomed in to a particular spot and when the user taps next it zooms out and then displays the next image. So I'm not sure if the proposed solutions fits?
Apple's docs recommend against trying to load single images that are larger than 1024x1024. You should look into using CATiledLayer instead, to load pieces of the images as needed.
You can have a look at this Apple sample:
http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010080
It shows how to load big images, breaking them in tiles for different zoom levels.
You can't see all those pixels at any given time, so there is no need to load them all. Load lower-res copies ("big-thumbnails") to view the complete image, then selected sub-tiles, maybe of 2 or more different resolution sets, after the user zooms in.
The CATiledLayer API may be able to handle some of the latter for you.

How to solve Memory Warning Level-1,then Memory Warning Level-2?

I am using apple standard code for scrolling+zooming+paging after 10 image scrolling and paging my console gives Memory Warning Level-1,Then Memory Warning Level-2 and then crash how can i stop crash my application?Please help me.I have taken this code from http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html
Did you implement the -(void)didReceiveMemoryWarning ? You can release every images that you don't use at this moment.
Keeping all images in an array will prevent you of doing this. Instead, you should create a method that gives you the right image based on its index (like an array) but that manages a cache (i.e. using an array) that you can clean when memory warnings are issued. Also I don't know this sample project by heart but I guess that they use only three controls to display image on the left, current image and image on the left. If not, be sure that other views are released when not useful for display.
It seems the images you use is of greater size.Try to reduce the pixel size and use it.
All the Best.
Each big image must be treated as a set of tiles and load data from the ONLY tile or set of tiles which is / are currently being displayed on the screen.
I dont know exactly how this works but you can google for it, I guess.