I am creating an app that send photo on email,i have created gallery,now i want my app can write text on that photo and send it on email. Any suggestions? tutorials are acceptable.
Asked
Active
Viewed 105 times
0
-
use contexts and draw rect methods to draw text on image.. – vishy Oct 16 '12 at 11:08
2 Answers
1
Simplest but tricky, Add a UIView
inside a UIImageView
and a UILabel
, update with yourimage
and text
. Now take an UIImage
by capture screenshot here. and attach it with your email.
-
Do i have to put capture screen method in appdelegate because otherwise it dispaly error in this two line at "window" – Oct 16 '12 at 11:42
-
UIGraphicsBeginImageContext(self.window.bounds.size); [self.window.layer renderInContext:UIGraphicsGetCurrentContext()]; – Oct 16 '12 at 11:43
-
-
@chetan, dude!! You can place this code anywhere! Instead of `self.window` you should pass the `UIView` that I've given in answer. – Hemang Oct 16 '12 at 12:14
0
You can create UIImageView with image then place UILabel with clear background on image view, and finally make a UIImage using Core Graphics. Something like this:
UIImage *bcg = [UIImage imageNamed:@"image.png"];
UIImageView *imgView = [[UIImageView alloc] initWithImage:bcg];
imgView.frame = CGRectZero;//Some frame
[self addSubview:imgView];
[imgView release];
UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(0, imgView.frame.size.height - 20, imgView.frame.size.width, 20)];
text.backgroundColor = [UIColor clearColor];
text.text = @"Some text";
[imgView addSubview:text];
UIImage *resultImage = nil;
UIGraphicsBeginImageContext(CGSizeMake(self.bounds.size.width,
self.bounds.size.height));
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGSize imageSize = CGSizeMake(self.bounds.size.width,
self.bounds.size.height);
UIGraphicsBeginImageContext(imageSize);
[viewImage drawInRect:CGRectMake(0,
0,
imageSize.width,
imageSize.height)
blendMode:kCGBlendModeNormal alpha:1];
resultImage = UIGraphicsGetImageFromCurrentImageContext();
This method easier to debug than draw image and text in context.

Moonkid
- 881
- 7
- 17