码迷,mamicode.com
首页 > 其他好文 > 详细

7. Quartz2D 绘制水印

时间:2015-02-17 20:59:39      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIImage *image = [self waterMaskImage];
    
    UIImageView *iv = [[UIImageView alloc]initWithImage:image];
    
    [self.view addSubview:iv];
}

-(UIImage *) waterMaskImage{
    CGSize imageSize = CGSizeMake(320, 200);
    //1. 建立图像的上下文,需要指定新生成的图像大小
    UIGraphicsBeginImageContext(imageSize);
    //2. 绘制内容
    UIImage *image = [UIImage imageNamed:@"1.png"];
    [image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];

    //3.添加水印文字
    NSString *str = @"我的水印";
    [[UIColor blueColor]set] ;
    [str drawInRect:CGRectMake(0, imageSize.height-30, imageSize.width-20, imageSize.height) withFont:[UIFont systemFontOfSize:16] lineBreakMode:(NSLineBreakByTruncatingTail) alignment:(NSTextAlignmentRight)];
    
    //4.获取到新生成的图像,从当前上下文获取到新绘制的图像
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
}

@end

 

7. Quartz2D 绘制水印

标签:

原文地址:http://www.cnblogs.com/wlxm/p/4295419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!