Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Last active March 21, 2016 05:58
Show Gist options
  • Save fhefh2015/7ea0497f403d4d468e84 to your computer and use it in GitHub Desktop.
Save fhefh2015/7ea0497f403d4d468e84 to your computer and use it in GitHub Desktop.
图片添加水印
//
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment