当前位置:首页 > 未命名 > 正文内容

Objective-C UIImage存沙盒与从沙盒读取

8年前 (2017-06-06)未命名
// 保存图片并返回路径
- (NSString *)saveImage:(UIImage *)tempImage
{
    NSString *image_fileType = @"";
    if (UIImagePNGRepresentation(tempImage) == nil) {
        image_fileType = @"JPEG";
    }else{
        image_fileType = @"PNG";
    }
    NSString *imageName = [NSString stringWithFormat:@"/%d.%@",1000000+(arc4random() % 999999999),image_fileType];
    NSData * imageData = UIImagePNGRepresentation(tempImage);
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * documentsDirectory = [paths objectAtIndex:0];
    // Now we get the full path to the file
    NSString * fullPathToFile = [documentsDirectory stringByAppendingString:imageName];
    // and then we write it out
    [imageData writeToFile:fullPathToFile atomically:NO];
    return fullPathToFile;
}

// 根据路径获取对应的图片
-(UIImage *)readImage:(NSString *)fullPathToFile{
    NSString * path = fullPathToFile;
    NSData * data = [NSData dataWithContentsOfFile:path];
    UIImage * image = [UIImage imageWithData:data];
    return image;
}

扫描二维码推送至手机访问。

版权声明:本文由小祥子的博客发布,如需转载请注明出处。

本文地址:http://www.xiaoxiangzi.com/post/45.html

相关文章

阿里妈妈cookie保持登录方案

阿里妈妈cookie保持登录方案

昨天研究阿里妈妈(淘宝客)的东西,为了做一个发送消息给公众号,然后随时生成可以返利的淘口令的功能。淘宝客我很久以前就注册过,但是不常用,因为去淘宝里买一个东西,要看他有没有返利还得去登另外个网址去查询...

新上线一款工具——google搜索

新上线一款工具——google搜索

 由于Google被国内封了,所以做了个google搜索结果调用的程序。 地址:http://www.xiaoxiangzi.com/tool/google.h...

Egret教程 egret.Shape 显示对象绘制图形

private drawGrid() { // 绘制     //指定填充色开始填充   &nb...

人像摄影

人像摄影

 上周日早上本来正在家睡觉,看到QQ群里有妹子求约,于是...地点:云大...

人像摄影

人像摄影

12.25地点:翠湖时间:2014年12月25日  地点:云大时间:2014年12月28日...

没有特长,凭什么拿高薪?

   今天跟大舅一起散步的时候,说到谁谁谁嫌工资低,大舅说“没有特长,怎么拿的到高工资?”。的确如此,以前做网站挣点钱,当然学这个的动力也是为了挣钱,网上接点小单,挣点小钱,发现多学一门技术...