保存圖片到沙盒

+ (void)saveImagePermanent:(UIImage *)currentImage withName:(NSString *)imageName{atom

    //高保真壓縮圖片可可將圖片壓縮,但圖片質量基本保持不變,第二個參數即圖片高保真參數。圖片

    NSData *imageData=UIImageJPEGRepresentation(currentImage, 0.3);string

     NSFileManager *fileManager = [[NSFileManager alloc] init];it

     NSString *createPath=[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,       NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"filePath"];io

    NSString *fullPath=[createPath stringByAppendingPathComponent:imageName];ast

    // 判斷文件夾是否存在,若是不存在,則建立file

    if (![[NSFileManager defaultManager] fileExistsAtPath:createPath]) {im

        [fileManager createDirectoryAtPath:createPath withIntermediateDirectories:YES attributes:nil error:nil];call

    } else { error

        NSLog(@"FileDir is exists.");

    }

    //圖片寫入文件

    [imageData writeToFile:fullPath atomically:NO];

}

相關文章
相關標籤/搜索