iOS 沙盒图片保存读取

//保存图片

-(void)saveImageDocuments:(UIImage *)image{

    //拿到图片
    UIImage *imagesave = image;
    NSString *path_sandox = NSHomeDirectory();
    //设置一个图片的存储路径
    NSString *imagePath = [path_sandox stringByAppendingString:@"/Documents/test.png"];
    //把图片直接保存到指定的路径(同时应该把图片的路径imagePath存起来,下次就可以直接用来取)
    [UIImagePNGRepresentation(imagesave) writeToFile:imagePath atomically:YES];

}

// 读取并存贮到相册

-(UIImage *)getDocumentImage{
    // 读取沙盒路径图片
    NSString *aPath3=[NSString stringWithFormat:@"%@/Documents/%@.png",NSHomeDirectory(),@"test"];
    // 拿到沙盒路径图片
    UIImage *imgFromUrl3=[[UIImage alloc]initWithContentsOfFile:aPath3];
    // 图片保存相册
    UIImageWriteToSavedPhotosAlbum(imgFromUrl3, self, nil, nil);
    return imgFromUrl3;
}

 

你可能感兴趣的:(相机,相册,沙盒)