iOS 选择的照片或者拍照的图片上添加日期水印
#import "NSDictionary+CLLocation.h"
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
NSString *strType = [info objectForKey:UIImagePickerControllerMediaType];
if ([strType isEqualToString:@"public.image"]) //当选择的类型是图片
{
__block NSMutableDictionary *imageMetadata = nil;
NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:asset.defaultRepresentation.metadata];
//控制台输出查看照片的metadata
self.picDataInfo = imageMetadata[@"{TIFF}"][@"DateTime"];
NSLog(@"%@**********", self.picDataInfo);
self.editeOrNot = YES;
UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"]; //先把图片转成NSData
self.image = image;
[reader dismissViewControllerAnimated:YES completion:nil]; //关闭相册界面
self.imageView = [CRMFactory createImageViewWithFrame:CGRectMake(15, self.takePhotoButton.frame.origin.y, 60, 60) image:image];
[self.view addSubview:_imageView];
//看大图
self.imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPic)];
[self.imageView addGestureRecognizer:tap];
self.takePhotoButton.frame = CGRectMake(15 + 60 + 15, self.takePhotoButton.frame.origin.y, 60, 60);
UIImage *scaleImage = [CRMDatahandle scaleFromImage:image];
UIImage *waterPoint = [self addText:scaleImage text:self.picDataInfo];
NSData *data = UIImageJPEGRepresentation(waterPoint, 1.0);
self.picName = [CRMDatahandle picName];
[self uplosaToServersice:data];
}
failureBlock:^(NSError *error) {
}];
}
}
#pragma mark - 添加水印
- (UIImage *)addText:(UIImage *)img text:(NSString *)mark {
if (mark.length != 0) {
} else {
//将时间戳转换成时间
NSDate *date = [NSDate date];
// 限定格式
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@" yyyy-MM-dd hh:mm:ss"];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"china"];//时区名字或地区名字
[formatter setTimeZone:timeZone];
mark = [formatter stringFromDate:date];
}
int w = img.size.width;
int h = img.size.height;
UIGraphicsBeginImageContext(img.size);
[img drawInRect:CGRectMake(0, 0, w, h)];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:25],
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName : [UIColor redColor],
NSTextEffectAttributeName: NSTextEffectLetterpressStyle
};
[mark drawInRect:CGRectMake(0, h - 40, w , 40) withAttributes:attribute];
UIImage *aImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return aImage;
iOS 选择的照片或者拍照的图片上添加日期水印的更多相关文章
- Office WORD如何在图片上添加文字
如图所示,在图片格式中选择图片衬于文字下方即可,这样看起来感觉就像在图片上直接加字一样,没有生硬的感觉. 最终效果: Word如何在图片上添加文字Word如何在图片上添加文字Word如何在图片上添加文 ...
- python 图片上添加数字源代码
最近因工作需要,需要在图片上添加数字,查询了资料,自己写了一个方法,并进行了测试,由于代码用到了PIL库,需要下载安装,下载地址:http://www.pythonware.com/products/ ...
- python 图片上添加文字
import PIL from PIL import ImageFont from PIL import Image from PIL import ImageDraw #设置字体,如果没有,也可以不 ...
- python如何在图片上添加文字(中文和英文)
Python在图片上添加文字的两种方法:OpenCV和PIL 一.OpenCV方法 1.安装cv2 pip install opencv-python 2.利用putText方法来实现在图片的指定位置 ...
- [转]微信小程序开发之从相册获取图片 使用相机拍照 本地图片上传
本文转自:http://blog.csdn.net/qq_31383345/article/details/53014610 今天遇到微信小程序的用户头像设置功能,做笔记. 先上gif: 再上代码: ...
- 微信小程序开发之从相册获取图片 使用相机拍照 本地图片上传
1.index.wxml <!--index.wxml--> <button style="margin:30rpx;" bindtap="choose ...
- java在图片上添加文字
业务需求要在图片上添加水印.下面粘出代码供自己和大家分享 package com.pro.drawTextOnImg; import java.awt.Color; import java.awt.F ...
- C#在图片上添加文字代码
创建.NET WinForm程序,设置项目的默认命名空间为Keleyi.Com,在窗体上添加一个PictureBox控件pictureBox_keleyi_com和一个Button控件button_A ...
- python PIL图像处理-图片上添加文字
首先需要安装库pillow cmd安装命令:pip install pillow 安装完后,编写脚本如下: from PIL import Image, ImageDraw, ImageFont de ...
随机推荐
- C#连接Sql Serve数据库及增,删,改操作
一:连接. string sqlconn = "server=主机名;database=数据名;integrated security=true" //integrated sec ...
- LoadLibrary函数定位DLL顺序
用LoadLibrary此函数来加载动态链接库到内存,Window 定位DLL的搜寻路径如下: 当前进程的可执行模块所在的目录. 当前目录. Windows 系统目录.GetSystemDirecto ...
- Linux QT
Check system version 1. cat /proc/version mike@sp-ThinkPad-X220:~$ cat /proc/versionLinux version 3 ...
- NetBios 的结构体详解
[NetBios 的结构体详解] NetBIOS是早期的局域网传输协议. 1.结构体. 2.命令 NetBIOS命令的使用方式有两种,即等待和非等待(或称为同步与异步)方式. 如果命令码的高阶位是0时 ...
- R随笔(2)
1,查看R中的变量模式(对象的数据类型)mode() 2,因子(factor), table()可以获取多个因子的交叉表,可以知道每个因子出现的次数 > g<-c("f&quo ...
- Light OJ 1027 - A Dangerous Maze (数学-期望)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1027 题目大意: 一个迷宫, 有n个门,选择一个门花费为|ai|, 如果选择的 ...
- wamp如何添加多个站点
1.打开wamp目录下的bin目录下的apache/conf/extra/httpd-vhosts.conf文件(虚拟目录配置文件),修改文件:在num01下创建index.php文件,输出01,:在 ...
- JavaScript的继承
原型继承的实现 1 简化版本 function SuperClass(){...} function SubClass(){...} SubClass.prototype=new SuperClass ...
- Visio 2007中进行数据库建模时如何显示字段类型以及概念名称
关于在VISIO中进行数据库建模时如何显示字段类型,以及注释的 1 如何显示字段类型: 在visio菜单上--->点击数据库--->选项--->文档 打开后选择表这项,在上 ...
- JavaWeb 学习001-登录页面-Servlet
那什么是Servlet呢? 我理解的Servlet 就是一个中间媒介,jsp页面原本需要一些操作,但是现在让jsp页面只是显示就好,把操作的工程转移给Servlet中. 使用Servlet时候有个固定 ...