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;

}

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

  1. Office WORD如何在图片上添加文字

    如图所示,在图片格式中选择图片衬于文字下方即可,这样看起来感觉就像在图片上直接加字一样,没有生硬的感觉. 最终效果: Word如何在图片上添加文字Word如何在图片上添加文字Word如何在图片上添加文 ...

  2. python 图片上添加数字源代码

    最近因工作需要,需要在图片上添加数字,查询了资料,自己写了一个方法,并进行了测试,由于代码用到了PIL库,需要下载安装,下载地址:http://www.pythonware.com/products/ ...

  3. python 图片上添加文字

    import PIL from PIL import ImageFont from PIL import Image from PIL import ImageDraw #设置字体,如果没有,也可以不 ...

  4. python如何在图片上添加文字(中文和英文)

    Python在图片上添加文字的两种方法:OpenCV和PIL 一.OpenCV方法 1.安装cv2 pip install opencv-python 2.利用putText方法来实现在图片的指定位置 ...

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

    本文转自:http://blog.csdn.net/qq_31383345/article/details/53014610 今天遇到微信小程序的用户头像设置功能,做笔记. 先上gif: 再上代码: ...

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

    1.index.wxml <!--index.wxml--> <button style="margin:30rpx;" bindtap="choose ...

  7. java在图片上添加文字

    业务需求要在图片上添加水印.下面粘出代码供自己和大家分享 package com.pro.drawTextOnImg; import java.awt.Color; import java.awt.F ...

  8. C#在图片上添加文字代码

    创建.NET WinForm程序,设置项目的默认命名空间为Keleyi.Com,在窗体上添加一个PictureBox控件pictureBox_keleyi_com和一个Button控件button_A ...

  9. python PIL图像处理-图片上添加文字

    首先需要安装库pillow cmd安装命令:pip install pillow 安装完后,编写脚本如下: from PIL import Image, ImageDraw, ImageFont de ...

随机推荐

  1. map创建JSONObject对象

    public static void mapToJSONObject(){ Map<String, Object> map = new HashMap<String,Object&g ...

  2. List<Object>转换为JSONArray二

    package com.beijxing.TestMain; import java.util.ArrayList; import java.util.Collection; import java. ...

  3. asp.net Ajax和web services

    新建一个web服务 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...

  4. DirectX12 Samples 学习笔记 – PredicationQueries

    一.效果 这是一个比较简单的sample,运行sample可以看到,当红橙色长方形完全覆盖白色正方形时,白色正方形不显示,其他情况,均显示白色正方形. 二.实现 Render主要由三个部分组成 1.F ...

  5. Git项目存放位置在导入Eclipse前不能存放在Eclipse Workspace

    这篇帖子的背景: 本人想将一个git项目导入至Eclipse的Workspace中,并且该项目的所有git信息.但是,该git项目在导入之前,就已经存放在Eclipse的Workspace中.在将该g ...

  6. 解决:eclipse 非正常关闭,导致无法正常启动

    eclipse 无法正常启动: !ENTRY org.eclipse.ui.navigator 4 2 2016-09-07 11:23:54.181 !MESSAGE 从插件调用代码时出现问题:“o ...

  7. js 让浏览器全屏模式的方法launchFullscreen

    浏览器全屏模式的启动函数requestFullscreen仍然需要附带各浏览器的js方言前缀 // 判断各种浏览器,找到正确的方法 function launchFullscreen(element) ...

  8. ZT 螨虫知识2

    病情分析:过敏是治不好的,只能做到避免接触.指导意见:螨虫的话就不要跟狗多接触,狗的寄生虫很多,还有草地,尤其是狗经常去的地方,草地就是螨虫的传播介质.你是过敏性体质除了被免过敏性源外,还要增强体质, ...

  9. ORA-20000:ORU-10027:buffer overflow,limit of 2000 bytes.

     ORA-20000:ORU-10027:buffer overflow,limit of 2000 bytes.  这是因为在过程中用到了dbms_output.put_line()在服务器端输出信 ...

  10. LSD-SLAM深入学习(2)-算法解析

    前言 在LSD-SLAM深入学习(1)中我们已经完成基本的安装与测试,在此我们继续解析算法与代码,由于lsd-slam本身利用了一部分李群与李代数的知识,需要一定的数学功底. 个人理解错误的地方还请不 ...