Thumbnail Image Viewer

I want to show some images as thumbnails in the View controller, but I don't know how to do this. Can someone please give me some ideas or sample code.

+4
source share
2 answers

Are you asking how to create thumbnails from larger images or how to create a view controller that displays them beautifully?

Creating a view controller:

You can use the TTPhotoViewController from the Three20 project ( description ), which acts similar to the iPhone's built-in camera roll to view images.

You can see the code for the Scrolling sample from the apple, which is mentioned in this question about using it for sketches .

If you want to create it yourself, you can use the GridView from moriarty library , either as a large grid in UIScrollView , or as a more efficient line by line in UITableView . There was a previous question about optimized image loading in UIScrollView .

Thumbnailing large images:

The easiest way to scale an image is to simply display it in a UIImageView with the frame set to the smaller size you need - it scales for you.

If you want to save a thumbnail or care about memory usage, you can create a hard version. The sample code below is taken from this blog post and can be added to UIImage as a category method:

 - (UIImage*) imageScaledToSize: (CGSize) newSize { UIGraphicsBeginImageContext(newSize); [self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; } 

Finally, here is the previous question about masking around corners in the image , similar to the application icons that are used on the main screen.

Added

Using the built-in image thumbnail:

There is a nice feature called CGImageSourceCreateThumbnailAtIndex that understands inline thumbnails in specific image data formats. You can see a useful code example for this in the โ€œCreating Thumbnail Image from Image Sourceโ€ section of Apple's I / O Programming Guide .

+36
source

There are several problems with thumbnails; Perhaps you could clarify which of you are most concerned about?

  • How to display a smaller version of an existing image

  • How to speed up paging by caching thumbnails (instead of just dynamically compressing the originals)

  • How to allow user to view page thumbnails

  • How to synchronize thumbnails with originals, in case your images are editable or the user can add to them

0
source

All Articles