iOS 选择的照片或者拍照的图片上添加日期水印

1..引入框架

#import "CLLocation+GPSDictionary.h"
#import "NSDictionary+CLLocation.h"

#import <AssetsLibrary/AssetsLibrary.h>

2.

- (void) imagePickerController: (UIImagePickerController*) reader
 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;

}

时间: 2024-10-17 08:59:42

iOS 选择的照片或者拍照的图片上添加日期水印的相关文章

在图片上添加文字水印

1 <?php 2 /** 3 打开任何一种格式的图片 在图片的中间加上一个文字水印 保存 4 只是保存下来 并不会输出到浏览器 5 */ 6 function imagewater($filename,$string){ 7 //获得图片的属性 8 list($width,$height,$type) = getimagesize($filename); 9 //可以处理的照片的类型 10 $types = array(1=>"gif",2=>"jpeg&

python 图片上添加文字

1 import PIL 2 from PIL import ImageFont 3 from PIL import Image 4 from PIL import ImageDraw 5 6 #设置字体,如果没有,也可以不设置 7 font = ImageFont.truetype("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",13) 8 9 #打开底版图片 10 imageFile = "base.png&qu

图片操作,图片上放个水印图片

知识点: 1.先创建一个Image,再创建一个水印图片Image,再创建画布Graphic 问题: 图片上放置一个水印图片 解决方案 1 <%@ WebHandler Language="C#" Class="ShuiYin" %> 2 3 using System; 4 using System.Web; 5 using System.Drawing; 6 7 public class ShuiYin : IHttpHandler { 8 9 publ

opencv在图片上添加文字

/****************************************** func:cvText desc:put text on an image @param img The image pointer which we want to put text on @param text the text pointer @param x the x coordinate @param y the y coordinate @return null ****************

python 图片上添加数字源代码

最近因工作需要,需要在图片上添加数字,查询了资料,自己写了一个方法,并进行了测试,由于代码用到了PIL库,需要下载安装,下载地址:http://www.pythonware.com/products/pil/,下载Imaging-1.1.7.tar.gz后解压得到,Imaging-1.1.7,在命令行下运行setup.py进行安装 具体实现代码如下: # -*- coding: utf-8 -*-import PILfrom PIL import ImageFontfrom PIL import

【Android】在图片上添加文字

[Android]在图片上添加文字 在Edittext中插入图片 下载地址:http://www.devstore.cn/code/info/604.html

微信小程序开发之从相册获取图片 使用相机拍照 本地图片上传

1.index.wxml 1 <!--index.wxml--> 2 <button style="margin:30rpx;" bindtap="chooseimage">获取图片</button> 3 <image src="{{tempFilePaths }}" mode="aspecFill" style="width: 100%; height: 450rpx&qu

数往知来 JQuery 图片上传_水印 &lt;二十二&gt;

一.图片上传  :enctype='multipart/form-date 首先在进行文件上传时,添加form表单中的enctype属性指定enctype='multipart/form-date', 文件数据发送给服务端,并不是把文件路径发送给服务端了,它会随机生成一个分割字符串, 把每一个表单元素分割开 <form method='post' action='' enctype='multipart/form-date'> //这里的enctype是提交请求报文的报文体的一种编码格式, 默

淘宝店铺装修轮播图片上添加多个自定义链接

受朋友之托,抽了点时间研究了一下店铺装修模板,每个模板都不一样如果想实现一张轮播图片上有多个链接,在轮播的模块内必须支持自定义代码,也就是自己添加代码,我这里就不上图片了,只分析几块重要的代码. 首先我在dreamweaver生成如下代码: <img src="http://img03.taobaocdn.com/imgextra/i3/298665212/TB2pR3NaXXXXXbCXXXXXXXXXXXX_!!298665212.jpg" width="1920&