Add a date watermark to an IOS selected photo or picture

Source: Internet
Author: User

1.: Introduce frame #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"])//When the selected type is a picture
{
__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];
Console output view metadata of photos
Self.picdatainfo = imagemetadata[@ "{TIFF}"][@ "DateTime"];
NSLog (@ "%@**********", self.picdatainfo);
Self.editeornot = YES;
UIImage *image = [info objectforkey:@ "Uiimagepickercontrollereditedimage"]; Turn the picture into NSData first
Self.image = image;
[Reader Dismissviewcontrolleranimated:yes Completion:nil]; Close the album Screen
Self.imageview = [Crmfactory createimageviewwithframe:cgrectmake (SELF.TAKEPHOTOBUTTON.FRAME.ORIGIN.Y, 60, 60) Image:image];
[Self.view Addsubview:_imageview];
Look at the big picture
self.imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Showpic)];
[Self.imageview Addgesturerecognizer:tap];

Self.takePhotoButton.frame = CGRectMake (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-Add a watermark
-(UIImage *) AddText: (UIImage *) img Text: (NSString *) Mark {
if (mark.length! = 0) {
} else {
Convert timestamps to TIME
NSDate *date = [NSDate Date];
Qualifying formats
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[Formatter setdateformat:@ "Yyyy-mm-dd Hh:mm:ss"];
[Formatter Settimezone:[nstimezone timezonewithname:@ "GMT"];
Nstimezone *timezone = [Nstimezone timezonewithname:@ "China"];//time zone name or region name
[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, max) Withattributes:attribute];
UIImage *aimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
return aimage;}

Add a date watermark to an IOS selected photo or picture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.