iPhone - Knowing when an UIImageView has loaded its image - iphone

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.

Related

How do I blur (ios7 style) a section of an image in a UITableViewCell?

I've got a UIImageView that takes up the whole cell and shows an image. I'd like to blur the bottom third of the view in the iOS7 style (we're targeting iOS7). There will be a label over the blurred part.
The issue seems to be that I can't "screenshot" the UIImageView right as I am setting up the cell in tableView:cellForRowAtIndexPath: as it hasn't loaded yet. Although i've even tried setting up a timer for a 0.1 second delay and that also doesn't work.
I've tried the stuff on http://damir.me/posts/ios7-blurring-techniques
I've tried https://github.com/justinmfischer/7blur
I'd like to use the new screenshotting API drawViewHierarchyInRect:afterScreenUpdates:
I'd also like to use apple's sample code UIImage+ImageEffects
The only thing that has worked so far has been to just put a UIToolbar in but the performance is really slow. I don't need dynamic updates.
I've managed to get the following effect a few times but it has just tinted the view and hasn't actually blurred anything so I'm a bit confused.
Use UIImageEffects sample from apple
Make a Image View with a size of the lower portion you want to blur... and then set its image to a blurred one. also set its content mode to UIViewContentModeBottom for the proper clipping
Since your image isnt the size of the cell.. first get a temp image as it is being displayed in the cell by drawing a UIImage from it.. refer for the code here
How to capture UIView to UIImage without loss of quality on retina display
then blur that image
Load this image into a UIImage, blur the image, clip to fit the area that you want. Use UIImage+blur.h

Load multiple images on 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.

iPhone - Make a small image fill a custom larger button

I have a UIButton in which I want to insert an image that would stretch to the button size. The button property allow it to stretch "down" the included image to fit the button size, but I want to do the opposite : the thing is that my image is small, and I want it to grow if the button is bigger than the image.
How may I do this ?
Set the image as the background image of the button.
you can use property value Aspect Fit or something related to it.
I had same problem and after searching i found a good thread.
How do I scale a UIButton's imageView?
I will suggest you to set background image of button which will solve your problem.
And be careful if you are resizing image programatically it will take time to resize. If you have multiple images and you are resizing programatically do it on different background thread which will protect your main thread and GUI will not hang and set resized image on main thread.

UIScrollView hangs while loading images into UIImageView

I have a UIScrollView with paging enabled. All the images were loaded at the start and added to the UIImageViews, but I had a memory-issue as it were more images, so I decided to load the after next image while scrolling if the image isn't set yet. If i get a memory warning, I remove all images except of the current.
The problem is, that the scrollview hangs for a few milliseconds if I scroll.
I'm using
UIImage *image = [UIImage imageNamed:#"path/to/image.png"];
to load the images. If I use the method imageWithContentsOfFile, it cost alot more time.
Is there a way to show a pixelated image like in the default Photoapp until it's fully loaded?
Thanks for your answers in advance.
[UIImage imageNamed:]
caches images for you, so that's why it's better than imageWithContentsOfFile. Since these images are displayed in a table cell, presumably they don't need to be that large. What are the images dimensions on the file system? If you just put the UIImage in a UIImageView and depend on that for scaling, my guess is the scaling happens while you scroll. Can you create thumbnails for each image on the file system and use those?

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