博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
图片水印
阅读量:6861 次
发布时间:2019-06-26

本文共 1604 字,大约阅读时间需要 5 分钟。

 
 
 

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

转载于:https://www.cnblogs.com/Lu2015-10-03/p/5177724.html

你可能感兴趣的文章
vs编译obj给delphi用
查看>>
过游戏保护NP或TP的几种方法和思路
查看>>
equals和hashcode为什么要一起重写
查看>>
模态与非模态对话框的问题
查看>>
地对地导弹地对地导弹地对地导弹
查看>>
让div 充满整个body
查看>>
程序员保持快乐活跃的6个好习惯(转)
查看>>
找工作的一些感悟——前端小菜的成长
查看>>
jSON Call can throw but it is not marked with try
查看>>
Javascript图片裁切
查看>>
Android -- Serializable和Parcelable需要注意的
查看>>
Apache -- phpmyadmin导入文件过大
查看>>
我的友情链接
查看>>
一分钟看懂Docker的网络模式和跨主机通信
查看>>
数据中悲观锁和乐观锁的理解
查看>>
能想到登录失败是这原因么
查看>>
Shiro 权限管理filterChainDefinitions过滤器配置
查看>>
我的友情链接
查看>>
Python 文件I/Oday14
查看>>
回忆Spring IOC 几个注解&简单示例
查看>>