fhefh2015
3/21/2016 - 1:57 AM

图片添加水印

图片添加水印

//
//  ViewController.m
//  图片水印
//
//  Created by fhefh on 16/3/21.
//  Copyright © 2016年 fhefh. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIGraphicsBeginImageContext(CGSizeMake(200, 200));
    
    //添加图片
    
    UIImage *image = [UIImage imageNamed:@"dog"];
    
    [image drawInRect:CGRectMake(0, 0, 200, 200)];
    
    //添加文字水印
    
    NSString *textWater = @"这是一个测试";
    NSDictionary *textAttr = @{NSFontAttributeName: [UIFont systemFontOfSize:30], NSForegroundColorAttributeName:[UIColor blueColor]};
    
    [textWater drawAtPoint:CGPointMake(0, 0) withAttributes:textAttr];
    
    //添加图片水印
    UIImage *image2 = [UIImage imageNamed:@"dog2"];
    [image2 drawInRect:CGRectMake(100, 100, 80, 80)];
    
    UIImage *outImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:outImage];
    
    [self.view addSubview:imageView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end