添加水印logo和文字 iOS
来源:互联网 发布:安卓鼓机软件loopz 编辑:程序博客网 时间:2024/05/01 04:29
创建一个category文件
.h
#import <UIKit/UIKit.h>
@interface UIImage (ImageWaterPrint)
-(UIImage *)imageWater:(UIImage *)imageLogo waterString:(NSString*)waterString;
@end
.m
#import "UIImage+ImageWaterPrint.h"
@implementation UIImage (ImageWaterPrint)
-(UIImage *)imageWater:(UIImage *)imageLogo waterString:(NSString*)waterString{
UIGraphicsBeginImageContext(self.size);
//原始图片渲染
[self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
CGFloat waterX = 633;
CGFloat waterY = 461;
CGFloat waterW = 16;
CGFloat waterH = 16;
//logo的渲染
[imageLogo drawInRect:CGRectMake(waterX, waterY, waterW, waterH)];
//渲染文字
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle]mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:20],NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:[UIColor redColor]};
[waterString drawInRect:CGRectMake(0, 0, 300, 60) withAttributes:dic];
UIImage *imageNew = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); // 此处注意要最后写入关闭绘制
return imageNew;
}
@end
ViewController中
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self imageWaterPrint];
}
-(void)imageWaterPrint{
UIImage *image = [UIImage imageNamed:@"1"];
UIImage *imageLogo =[UIImage imageNamed:@"2"];
UIImage *imageNew =[image imageWater:imageLogo waterString:@"哲"];
UIImageWriteToSavedPhotosAlbum(imageNew, nil, nil, nil); // 将图片保存到手机相册中
}
@end
添加 <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能访问相册</string> iOS 10如果访问必须添加否则闪退
- 添加水印logo和文字 iOS
- UIImage添加水印(Logo+文字)
- iOS 图片添加文字水印
- DotNet为图片添加水印(LOGO及文字)
- ASP.NET 上传图片添加文字、Logo水印
- ffmpeg 添加水印LOGO
- java图片添加水印,包括文字水印和图片水印
- ios图片添加文字或者水印
- [iOS]图片添加文字或者水印
- IOS给图片添加文字水印
- iOS与Android 添加文字水印
- java 添加水印文字和图片
- 使用Java添加图片水印和文字水印
- 使用Java添加图片水印和文字水印
- 使用Java添加图片水印和文字水印
- PHP图片添加文字水印和图片水印
- ffmpeg 视频添加水印 logo
- ios-画一个图片水印和文字水印
- Android 提交数据到服务器
- abd闪退解决办法
- Linux查看进程和终止进程的技巧
- Android学习笔记--AIDL
- javaweb学习总结——Servlet开发(一)
- 添加水印logo和文字 iOS
- spring boot集成mybatis
- 飞机大战(上篇绘制)
- sleep和yield,join
- Spring Boot 之web Filter --不支持排序的使用
- CSS3 transform笔记
- SQL优化大全
- 线程安全集合
- C++标准库(STL)中的容器