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

图片水印

时间:2016-02-02 16:32:20      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

 技术分享
 
技术分享
 

Main.storyboard

技术分享

ViewController.m

//

//  ViewController.m

//  5B04.图片水印

//

//  Created by huan on 16/1/29.

//  Copyright © 2016 huanxi. All rights reserved.

//

 

#import "ViewController.h"

 

@interface ViewController ()

 

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

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    // 生成一张有水印的图片,一定要获取UIImage对象 然后显示在imageView

    //创建背景图片

    UIImage *bgImage = [UIImage imageNamed:@"scene"];

    //1.创建一个位图【图片】,开启位图上下文

    //2.size:位图大小

    //3.opaque:alpha 通道 YES:不透明/NO 透明 使用NO,生成的更清晰

    //scale 比例 设置0.0为屏幕的比例 获取生成图片大小

    //位图大小:20*20 生成一张:(20 *scale *20 *scale

    

    NSLog(@"当前屏幕的比例 %f", [UIScreen mainScreen].scale);

    UIGraphicsBeginImageContextWithOptions(bgImage.size, NO, 0.0);

    

    

    //2.画背景图

    

    [bgImage drawInRect:CGRectMake(0, 0, bgImage.size.width, bgImage.size.height)];

    

    //3.画水印

    //算水印的位置和大小

    CGFloat waterW = 80;

    CGFloat waterH = 60;

    CGFloat waterX = bgImage.size.width - waterW;

    CGFloat waterY = bgImage.size.height - waterH;

    UIImage *waterImage = [UIImage imageNamed:@"logo"];

    [waterImage drawInRect:CGRectMake(waterX, waterY, waterW, waterH)];

    

    //4.从位图上下文获取 当前编辑的图片

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    //5.结束当前位置编辑

    UIGraphicsEndImageContext();

    //6.显示在UIImageView

    self.imageView.image = newImage;

}

 

@end

技术分享

图片水印

标签:

原文地址:http://www.cnblogs.com/Lu2015-10-03/p/5177724.html

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