日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/5/22 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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; }

轉載于:https://www.cnblogs.com/tian-sun/p/5909953.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的iOS 选择的照片或者拍照的图片上添加日期水印的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。