iOS 将图片存到本地
2016-12-02 本文已影响1950人
南城同學
将图片以Data形式存到本地,并返回路径
- (NSString *)saveImg:(UIImage *)image withVideoMid:(NSString *)imgName{
if (!image) { //防止image不存在,存一个占位图
image = [UIImage imageNamed:@"posters_default_horizontal"];
}
if (!imgName) { //防止imgName不存在,获取一个随机字符串
imgName = [NSString uuid];
}
//png格式
NSData *imagedata=UIImagePNGRepresentation(image);
//JEPG格式
//NSData *imagedata=UIImageJEPGRepresentation(m_imgFore,1.0);
NSString *savedImagePath = [[PVRSandBoxHelper AlbumVideoImagePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", videoMid]];
[imagedata writeToFile:savedImagePath atomically:YES];
return savedImagePath;
}