Load multiple images on iPhone - iphone

So I have a UIButton, when said button is pressed a UIView is created which holds 10 UIImageViews, all of those have a size of 100x100. For every UIImageView there's an image with the size of 640x960, which I resize to fit the UIImageView. My problem is that every time I press the button there's a 1-2 second delay before the UIView gets created, but everything works fine if I remove the UIImageViews. Can anyone provide some help? Thanks in advance.

Loading and resizing 10 UIImageViews is going to cause delay. Create thumbnail versions of your images by pre-resizing them to 100x100 and load them instead of the large ones and there should be minimal delay.

Related

UIImage stutter on first load

I have a UIScrollview that zooms a PNG image in and out on a double tap. The way I have it set up, I create a few multiple sizes of the PNG image using UIGraphicsBeginImageContext/UIGraphicsEndImageContext and store all the UIImages in an NSMutableArray. I then show the correct image on screen by swapping a UIImageView's image to the correct UIImage based on the current zoom level (I do all this to show a nicely anti-aliased image at all times rather than scaling just the original image).
The problem I have is that the very first time the image gets swapped to one that hasn't been displayed before, there is a slight stutter. After the first time, I can zoom in and out all day and there is no stutter. I have tried the solutions suggested here and here but they did not fix the problem.
Currently, I found a workaround by swapping the image after 0.01 seconds, and canceling any pending swap requests in the meantime. This works ok but it's not a solid fix. Obviously there has to be a way to get the images in a ready state since they become ready after the first time they are displayed. Please help me!
You don't actually need to create different sizes of the png. What you should have is a UIImageView inside the scrollview with the original PNG as it's image. Then add this to your .m file (make sure you have in your header file.
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return theImageView;
}
you can also set the max and minimum zoom scale by doing this:
[scrollview setMinimumZoomScale:0.5];//will be half size
[scrollview setMaximumZoomScale:3.0];//will be 3X
Doing the above will automatically set up the pinch zoom for you. THen you just need to code in to listen for the double tap and tell it to do this:
[scrollview setZoomScale:1.0 animated:YES];//returns it back to original size
Hope this helps - let me know if not the effect you were looking for.
Cheers,
Michael

iPhone - Knowing when an UIImageView has loaded its image

I'm loading a 5MP image into an UIImageView calling self.imagecontainer.image = myUIImage. myUIImage is an image coming from the camera of the iPhone.
This takes some time before the image can be seen on screen, and even if I can reduce this time, I need to start a process when the image is really displayed on the screen.
How may I know that the image is loaded and displayed, and not just still being processed by the UIImageView ?
Well... first thing is you shouldn't be setting a 5MP image in an imageView. An imageView is meant for on screen display only and even though it scales the image you set for display purposes the original is retained so your memory footprint goes way up. If you do this at best you will have a poor performing app that deals with lots of memory warnings. At worst, you'll crash often.
So, you should resize your image to the smallest size that meets your onscreen display needs and then set that image within your imageView. This is my favorite blog post on how to resize images: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way.
Now, to your question. You can't know for sure when the image is displayed but it will happen so quickly once you scaled you can just assume it is displayed as soon as you set it. So do your scaling on a background thread. When the scaling is done, send a message to the main thread to set the scaled image in the imageView and then do whatever you want.

iOS: How to display multiple images dynamiclly in imageview?

Hi I am new to iPhone.
What I need is, have to display only one image in one case, two images in another case like wise and for that I am using a UIImageview with IBOutlet.
How can I display multiple images in single imageview?
Please help me post some code.
Thank you.
An UIImageView can only display one image at a time. You will either have to use several UIImageViews or compose your images into one file before displaying it.
I think you should subviews ot type UIImageView to your main UIImageView.
The "hard" task will be to compute the boundaries of each subview, according to the prefered layout. Use the image property of UIImageView to set the image for each subview (don't worry about resizing, UIImageView will do the work for you)

UIImageView is resizing

I have an issue with uiimageviews resizing at run time. On one view I have more than a dozen uiimageviews contained within a uiscrollview. The images are assigned at design time. The uiimageview's are all the same size. The mode is set to Aspect Fill for all uiimageviews. At run time the images appear correctly in the view.
On a second view I have only 9 uiimageviews. These uiimageviews will display up to nine of the images selected from the first view. There are three images across and three images down. The uiimageview at design time is the same size as on the first view. The uiimageview image is assigned an image that is loaded into an array. All the uiimageviews are sized the same and they also have the mode set to Aspect Fill. The images are assigned at run time using image1.image = xxx. Where xxx is an image stored in an array.
However, on this second view, the images are not all the same size. The height of the image changes dynamically. The same image displayed in a different uiimageview on the view will be different sizes. It is the height of the uiimageview that changes. In some cases the image will fill the uiimageview differently. It is like the mode changes dynamically.
I've tried using different modes and nothing changes.
Any ideas on what is happening?
try resetting the frame of UIImageview's object (of same size which you set at the design time) after setting its image property...

Resizing images on iPhone for UITableView image

I'm using a sectioned TableView, and I want to show an image on the left side of the cell.
If I pick one from the photo library (out of the example photos in simulator) and set it as UITableViewCell.imageView.image, it takes up the whole screen.
How can I resize the image so that it fits exactly into the cell's image view?
Thanks,
Yassin
This is basically the same question as How to scale a UIImageView proportionally ?, which has a good answer.
Add that category to your project and call it with the size of your view. I've used the code and it works well.