I’ve got a need to write an app that can take a picture and then I want to be able to preview it and overlay a graphic and maybe some text and then save it back to the image library.
So, my user would start my app which would then use UIImagePickerController to access the camera and get the data of the image through delegation.
Then I want to display it on the screen and then present controls to add a visible image (or logo specifically) and give the user the option to add maybe one or two lines of text which are then positioned on an area of the picture.
The user will then click save and the resulting composited image will be written to the camera roll/photo library which then the user can upload the image to twitter, facebook etc as needed (I don’t want the overhead of implementing OAuth2 that can be someone else’s problem).
So, what I need to know is which of the many libraries available in the SDK will let me do this? CGImage? And given my overlay logo will be a transparent PNG, how do I overlay one on the other?
I’ve heard that you can present with CALayer but I don’t know how you then grab all the layers together (flatten them).
In PHP you would use something like imagecopymerge(), i’m having trouble figuring out the equivalents.
I don’t want to pass the data to a webserver and back as I know it can be done natively.
Thanks
Well to add text onto of the image i’m sure you can just use a textfield to get input then put the text into a label. This part can be done a few different ways but is fairly easy.
As far as grabbing a combined image of all the layers you can use Quartz.
Every
UIWindow(inherited fromUIView) andUIViewis backed by a CALayer. TheCALayer/-renderInContext:method lets you render a layer and its sublayers to a graphics context. So, to grab a snapshot of the entire screen, you can iterate through each window on the screen and render its layer hierarchy to a destination context. Once finished you can get the screenshot image via theUIGraphicsGetImageFromCurrentImageContextfunction, as shown below.Note that,
CALayer/-renderInContext:captures only your UIKit and Quartz drawing. It does not capture OpenGL ES or video content.…..
As far as uploading to Facebook and Twitter take a look at ShareKit. It’s a drag and drop library for sharing with Facebook, Twitter, Tumblr, email, etc.. Having this would add value to your app. I’d recommend implementing it.