最初是在程序中要用到从系统相册选取图片后保存到沙盒目录中,从系统相册得到 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> 后,由iPhone相机拍照得到的图片就会自动