3

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.

  • The ImageView will display the selected photo.
  • The TextField enables the user to enter some text.
  • When the Test Button is tapped, the text entered will appear on the image.
  • When the Confirm Button is tapped, the image (with the text on it) will be saved.

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).

logancautrell
  • 8,762
  • 3
  • 39
  • 50
Lloydworth
  • 743
  • 6
  • 20
  • 38
  • possible duplicate of [converting UIVIew as Image?](http://stackoverflow.com/questions/5469351/converting-uiview-as-image) – logancautrell Nov 04 '11 at 03:04
  • Not exactly a duplicate of that. The function i wanted is more like an image-editing kind of function. I just need ideas of how to insert images or text to the selected photo. If possible, also add effects to the text. For example, bold it or adding a shadow effect to the text. – Lloydworth Nov 04 '11 at 03:23
  • For example, some mobile applications have this function that allows you to select a photo from the gallery and it has some default cliparts (hats, hair, moustache, etc..) that you can place on the selected photo. After you're done, you are able to save it as an image. Yes, thats the function i want. – Lloydworth Nov 04 '11 at 03:27

2 Answers2

1

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?.

Community
  • 1
  • 1
logancautrell
  • 8,762
  • 3
  • 39
  • 50
  • 1
    So i will just put the textfield on top on the imageview for the user to enter the text? And is the values of my imageview? – Lloydworth Nov 04 '11 at 03:05
  • No, you need the superview of both the image view and the label. This has to be in the coordinate system of the layer you are asking to render. – logancautrell Nov 04 '11 at 03:06
1

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.

Prashant Bhayani
  • 692
  • 5
  • 18