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 ...
随机推荐
- DIOCP单元文件应用场景
diocp.coder.tcpServer是用来做文件传输的 diocp.tcp.server这个是用来做通讯的
- linux系统数据盘挂载教程
将数据盘挂载为/www命令:#mkdir /www & mount /dev/sdb1 /www ----------------------------------------------- ...
- JAVA异常初步
1,1个图.Throwable是所有异常类的老祖宗,万恶之源.Error正常是系统级错误,控制不了,Exception类又分RuntimeException及别的异常,RuntimeException ...
- [整理]S-Record数据格式解析
S-Reord是一种由摩托罗拉公司创建的文件格式(不得不说,摩托罗拉厉害啊,SPI和S-Record都是他们创造的).S-Record的基本字符为ASCII字符,用以表示相应的十六进制数据.该数据格式 ...
- Mapped Statements collection does not contain value fo
Mapped Statements collection does not contain value for后面是什么类什么方法之类的: 错误原因有几种: 1.mapper.xml中没有加入name ...
- 九月二十八JS验证
js表单验证 js可用发来在数据被送往服务器前对HTML表单中的这些输入数据进行验证 被js验证的这些典型的表单数据有: >用户是否已填写表单中的必填项目: >用户输入的邮件地址是否是合法 ...
- NC 查询公司下所分配的组织,并存放字符串数组中
private String[] querkFather() { String sql = "select pk_org from org_orgs start with pk_father ...
- CSS浏览器兼容问题总结
为什么会出现浏览器兼容问题? 由于各大主流浏览器是不同的厂家开发的,所以使用的核心也不相同,架构代码很难重合,就会产生各种各样的bug. IE6中常见的css解析bug 1)默认高度(IE6)部分块元 ...
- 解决服务器Active Directory环境里Windows登录性能问题办法
Windows登录性能因素 当查找登录性能问题的原因时,考虑大量因素很重要.一些因素包括: 域控制器太接近用户 网络连接与可用的带宽 数据中心上的硬件资源(x64 vs.x86.内存等) 应用于用户和 ...
- Docker-3:Data Volume
Sometimes, applications need to share access to data or persist data after a container is deleted. ...