IOS第17天(1,Quartz2D图片水印)

****图片 水印

#import "HMViewController.h"

@interface HMViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation HMViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIImage *oldImage = [UIImage imageNamed:@"img"];
    
    // 开启上下文
    // size 新的图片大小
    // opaque YES 不透明 NO 透明
    UIGraphicsBeginImageContextWithOptions(oldImage.size, NO, 0.0);
    [oldImage drawAtPoint:CGPointZero];
    
    NSString *text =  @"我要高薪 !";
    NSDictionary *dict = @{
                           NSFontAttributeName : [UIFont systemFontOfSize:15],
                           NSForegroundColorAttributeName : [UIColor redColor]
                           
                           };
    [text drawAtPoint:CGPointMake(120, 170) withAttributes:dict];
    
    // 获取新的图片
    UIImage *newImage =  UIGraphicsGetImageFromCurrentImageContext();
    
    // 关闭上下文
    UIGraphicsEndImageContext();
    
    _imageView.image = newImage;
    
    // 把图片转换成png格式的二进制数据
    NSData *data = UIImagePNGRepresentation(newImage);
    
    // 写入桌面
    [data writeToFile:@"/Users/apple/Desktop/newImage.png" atomically:YES];
    
}

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

@end

 

posted @ 2015-09-01 17:15  iso  阅读(140)  评论(0编辑  收藏  举报