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?
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?
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.
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.
Apple's TheElements demo (AtomicElementViewController) has a great example on how to do this. And also how to create a reflection and bevelled look.