将UIImage保存到iOS照片库和对应程序沙盒中
来源:互联网 发布:网络销售金融聊天记录 编辑:程序博客网 时间:2024/06/08 06:12
1.保存到iOS照片库需要引入QuartzCore.framework框架,具体代码如下:
.h文件
#import<QuartzCore/QuartzCore.h>
UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UIImageView*imageView;
.m文件
UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage *temp = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(temp, nil, nil, nil);
2.保存到对应的沙盒目录中,具体代码如下:
NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:[NSStringstringWithFormat:@"sms.gif"]]; // 保存文件的名称
BOOL result =[UIImagePNGRepresentation(imageView.image)writeToFile:filePath atomically:YES]; // 保存成功会返回YES
3,图片上写文字
+ (UIImage *)imageAddText:(UIImage *)img textArray:(NSArray *)textArray
{
int w = img.size.width;
int h = img.size.height;
UIGraphicsBeginImageContext(img.size);
[[UIColor blackColor] set];
[img drawInRect:CGRectMake(0, 0, w, h)];
NSInteger count = [textArray count];
for (int i= 0; i<count; i++) {
NSString *mark = [textArray objectAtIndex:i];
[mark drawInRect:CGRectMake(10, 30 + i*40, w - 10, 40) withFont:[UIFont systemFontOfSize:30]];
}
UIImage *aimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return aimg;
}
.h文件
#import<QuartzCore/QuartzCore.h>
UIImageView *imageView;
@property (nonatomic, retain) IBOutlet UIImageView*imageView;
.m文件
UIGraphicsBeginImageCont
[imageView.layerrenderInContext:UIGraphicsGetCurrentCont
UIImage *temp = UIGraphicsGetImageFromCu
UIGraphicsEndImageContex
UIImageWriteToSavedPhoto
2.保存到对应的沙盒目录中,具体代码如下:
NSArray *paths =NSSearchPathForDirectori
NSString *filePath = [[paths objectAtIndex:0]stringByAppendingPathCom
BOOL result =[UIImagePNGRepresentation
3,图片上写文字
+ (UIImage *)imageAddText:(UIImage *)img textArray:(NSArray *)textArray
{
int w = img.size.width;
int h = img.size.height;
UIGraphicsBeginImageContext(img.size);
[[UIColor blackColor] set];
[img drawInRect:CGRectMake(0, 0, w, h)];
NSInteger count = [textArray count];
for (int i= 0; i<count; i++) {
NSString *mark = [textArray objectAtIndex:i];
[mark drawInRect:CGRectMake(10, 30 + i*40, w - 10, 40) withFont:[UIFont systemFontOfSize:30]];
}
UIImage *aimg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return aimg;
}
0 0
- 将UIImage保存到iOS照片库和对应程序沙盒中
- 将UIImage保存到iOS照片库和对应程序沙盒中
- 将UIImage保存到iOS照片库和对应程序沙盒中
- IOS-UIImage保存到iOS照片库和对应程序沙盒中
- 将UIImage保存到相册
- iOS-将图片保存到照片相册中
- ios 保存图片到系统照片库
- 【IOS开发】UIImage 和 NSString的保存
- 【IOS开发】UIImage 和 NSString的保存
- iOS下将照片保存到相册的三种方法
- iOS下将照片保存到相册的三种方法
- iOS下将照片保存到相册的三种方法
- 保存UIImage到文件--到本地自己的程序目录
- 将UIImage对象保存到JPG或者PNG文件中
- 将 UIImage 保存到磁盘,用什么方式最好?
- UIImage保存到相册
- 保存照片和视频到相册显示
- IOS-UIView转UIImage并保存到本地相册
- jsp - EL
- 19本Android经典教程+104个Github上火爆项目开源源码
- python中multiprocessing.pool函数介绍
- Unity3D研究院之Assetbundle的实战(六十三)
- OpenSessionInViewFilter
- 将UIImage保存到iOS照片库和对应程序沙盒中
- Java 类中的protected关键字
- 其实不是每一个魅力的人哦那件事
- 推送证书申请
- Unity3D研究院之Assetbundle的原理(六十一)
- linux下载指定网址文件 wget
- 影响postgresql性能的几个重要参数
- shell中$*与$@的区别
- iOS APP 架构漫谈(一)