views:

200

answers:

3

I'm looking to stitch some images together, with the images always being added to the bottom of the previous image.

e.g. I have images A,B and C. I would like them to appear on top of one another like:

A
B
C

What's the best way to do this?

Thanks!

+1  A: 

Create a UIView, then add multiple UIImageView instances as subviews. Set the image for each subview, and you're all set. If you have a fixed set of images (or at least a fixed number), you can do all of the layout in InterfaceBuilder. Otherwise, it's just a matter of creating a new UIImageView, then calling addSubView: on the parent view.

http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/addSubview:

If the set of images will be taller than the screen, you'll want to use a UITableView.

Mark Bessey
Why not a UIScrollView?
Nimrod
The TableView will automatically flush the imageviews when they're off-screen. Most times, that'd be what you want, as it minimizes memory usage.
Mark Bessey
+1  A: 

OH, you want to tile the images, not composite them. In that case, this blog post might help: http://www.realdevelopers.com/blog/?p=415

The idea is that you create a new CGContextRef of your desired image size, draw your original images onto it at the appropriate locations, and then create a new UIImage out of the CGContextRef.

Dave DeLong
+1  A: 

I did this in the end:

+ (UIImage *)joinImages:(UIImage *)im1 secondImage:(UIImage *)im2 thirdImage:(UIImage *)im3
{
//Joins 3 UIImages together, stitching them vertically
CGSize size = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(size);

CGPoint image1Point = CGPointMake(0, 0);
[im1 drawAtPoint:image1Point];

CGPoint image2Point = CGPointMake(0, im1.size.height);
[im2 drawAtPoint:image2Point];

CGPoint image3Point = CGPointMake(0, im1.size.height +im2.size.height);
[im3 drawAtPoint:image3Point];

UIImage* finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return finalImage;
}
mac_55
+1 clever! (15 characters)
Dave DeLong