views:

1248

answers:

3

Hi,

I want to stitch 2 pieces of png side by side. In Cocoa, I would use [NSImage initWithSize], and then just drawInRect.

But UIImage don't have initWithSize class, how would I do this now?

+6  A: 

Use UIGraphicsBeginImageContext(), draw in it, then use UIGraphicsGetImageFromCurrentImageContext(). Remember to pop the context with UIGraphicsEndImageContext() afterwards.

You should avoid creating an extra image if you simply want to display the two images onscreen, due to the limited memory available on the device. Instead, display them using appropriate drawInRect: calls to avoid copying.

millenomi
+1  A: 

if you're trying to create a new image with the two component images in it, try using UIGraphicsBeginImageContext(size) and UIGraphicsGetImageFromCurrentImageContext(). Together, those should let you create a new image of the size you'd like to work with, draw into it, and pull out a fresh UIImage object.

Ben Gottlieb
A: 

Apple's TheElements demo (AtomicElementViewController) has a great example on how to do this. And also how to create a reflection and bevelled look.

yooj