Reputation: 763
I'm developing an image editing application on the iPad. It is like a function where you can write text into an image and then save it.
The user will be able to select an image from the iPad's photo gallery. When a photo is selected, it will navigate to another view showing an ImageView, TextField, 'Test' button and 'Confirm' button.
I know how to code the part that allows the user to select an image from the photo gallery and navigating to another view showing the selected image on the ImageView.
So i need help on how to display the text on the image and saving the image (with the text on it).
Upvotes: 3
Views: 7249
Reputation: 692
add a label in your UIImageView object (which contains a image from photo gallery).set frame of this label when ever you want text on image. you can add it by this:
[yourUiimageView addSubview: yourLabel];
then crop your image by this:
UIGraphicsBeginImageContext(yourUiimageView.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[yourUiimageView.layer renderInContext:ctx];
UIImage *albumThumbImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImagePNGRepresentation(albumThumbImage);
Now save this data to document directory. this image will contains the image with text.
Upvotes: 1
Reputation: 8772
There are a couple of ways. The easiest it so just take a snapshot of the super view using this code.
CGRect rect = CGRectMake(<your values>);
UIGraphicsBeginImageContext(rect.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
This is a duplicate of How to convert UIView as UIImage?.
Upvotes: 1