ios - 如何从 ALAsset 保存压缩的 JPEG

标签 ios

我有一个从 ALAssetLibrary 检索到的对象 ALAsset 我想推断压缩 JPEG 以便将它发送到 Web 服务。

有什么建议从哪里开始?

编辑: 我找到了一种从 ALAsset 中获取 NSData 的方法

ALAssetRepresentation *rappresentation = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rappresentation.size);
NSUInteger buffered = [rappresentation getBytes:buffer fromOffset:0.0 length:rappresentation.size error:&err];

但我找不到通过调整大小和压缩来减小图像大小的方法。 我的想法是有类似的东西:

UIImage *myImage = [UIImage imageWithData:data];
//resize image
NSData *compressedData = UIImageJPEGRepresentation(myImage, 0.5);

但是,首先,即使不调整大小,仅使用这两行代码 compressedData 也比数据大。 其次,我不确定调整 UIImage 大小的最佳方式是什么

最佳答案

你可以使用

[theAsset thumbnail]

或者;

压缩后可能会产生更大的文件,您需要调整图像大小:

+ (UIImage *)imageWithCGImage:(CGImageRef)cgImage scale:(CGFloat)scale orientation:(UIImageOrientation)orientation

关于ios - 如何从 ALAsset 保存压缩的 JPEG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10121450/

相关文章:

ios - 如何使用 Alamofire 多部分上传多张图片?

ios - 创建使用外部 Pod 的自定义 Pod

iOS。我可以在 Interface Builder 中为 UIScrollView 制作自定义 View 吗?

php - 智能识别不同账户为同一用户

ios - 如何扩展包含 UINavigationController 的 UIView

iphone - 将 pdf 文件请求从文档目录发送到 iPhone 中的(POST 方法)Web 服务?

ios - 在创建新 key 并删除旧 key 后,我在我的 iOS Xcode 项目中使用适用于 iOS 的 Google Maps SDK 的不受限制的 api key

ios - 如何添加图片下载等模糊效果

iphone - 需要帮助了解NSDictionary对象

ios - 如何在 Swift 项目中使用 Obj-c 库/自定义接口(interface)