#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *image = [UIImage imageNamed:@"菲哥"];
//开启位图上下文,位图上下文和view上下文没有关系,所以可以不在drawRect方法中绘制
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
//绘制原生的图片
[image drawAtPoint:CGPointZero];
//绘制文字
NSString *str = @"@神户牛肉";
NSMutableDictionary *textDict = [NSMutableDictionary dictionary];
textDict[NSForegroundColorAttributeName] = [UIColor grayColor];
textDict[NSFontAttributeName] = [UIFont systemFontOfSize:16];
[str drawAtPoint:CGPointMake(image.size.width * 0.74, image.size.height * 0.94) withAttributes:textDict];
//生成带水印的图片
UIImage *imageWater = UIGraphicsGetImageFromCurrentImageContext();
//关闭上下文
UIGraphicsEndImageContext();
_imageView.image = imageWater;
}
@end
来张@大菲 菲哥的照片
这里开始选的是一张jpg格式的图片,不知道为毛运行之后显示不出来,强制将格式改成png之后,就可以显示了。啥原因啊?