最初是在程序中要用到从系统相册选取图片后保存到沙盒目录中,从系统相册得到 ALAsset 对象,进而取得ALAssetRepresentation 对象后保存到沙盒中得到一个图片路径。
NSString *mediaType = [asset valueForProperty:ALAssetPropertyType];
NSString *fileName = [[asset defaultRepresentation] filename];
ALAssetRepresentation *representation = [asset defaultRepresentation];
Byte *buffer = (Byte *)malloc((unsigned long)representation.size);
NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:((unsigned long)representation.size) error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
[data writeToFile:filePath atomically:NO]; // 这样就把图片数据保存到了沙盒目录,filePath是由要保存到的沙盒目录和上面的fileName拼接的路径
将得到的图片路径filePath 在html页面中显示,若是使用 <img> 标签的话能够正常的显示图片,而换成 <div> 后,

本文讲述了在iOS应用中,从系统相册选取照片保存到沙盒时遇到的图片旋转90度问题以及使用CGImageRelease导致应用崩溃的内存管理问题。通过调整保存流程,避免手动释放CGImageRef对象,解决了图片方向和程序稳定性问题。
最低0.47元/天 解锁文章
5562

被折叠的 条评论
为什么被折叠?



