Ios 如何从压缩集保存压缩的JPEG

Ios 如何从压缩集保存压缩的JPEG,ios,Ios,我有一个从ALAssetLibrary检索到的对象ALAsset,我想推断一个压缩JPEG,以便将其发送到web服务 有什么建议从哪里开始吗 编辑: 我找到了一种从数据集中获取NSData的方法 ALAssetRepresentation *rappresentation = [asset defaultRepresentation]; Byte *buffer = (Byte*)malloc(rappresentation.size); NSUInteger buffered = [rappr

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

有什么建议从哪里开始吗

编辑: 我找到了一种从数据集中获取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);
但是,首先,即使不调整大小,仅使用这两行代码压缩数据也比数据大。 其次,我不确定调整UIImage大小的最佳方法是什么

[theAsset thumbnail]

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

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

ALAssetRepresentation
获取CGImage很容易:

ALAssetRepresentation repr = [asset defaultRepresentation];
// use the asset representation's orientation and scale in order to set the UIImage
// up correctly
UIImage *image = [UIImage imageWithCGImage:[repr fullResolutionImage] scale:[repr scale] orientation:[repr orientation]];
// then do whatever you want with the UIImage instance