Ios 从ALAsset获取实际的NSData(每次我获得更大的图像大小时)

Ios 从ALAsset获取实际的NSData(每次我获得更大的图像大小时),ios,iphone,objective-c,Ios,Iphone,Objective C,我试图做的是从ALAsset(Image)获取NSData,磁盘上的映像大小为75 KB,但当我试图从该资产获取NSData时,它返回的NSData大小非常大,我的问题是“如何从映像返回75 KB的数据而不是更大的数据” 我的代码: ALAssetRepresentation* representation = [asset defaultRepresentation]; CGFloat scale = 1; UIImage* image = [UIImage imageWithCGImage

我试图做的是从ALAsset(Image)获取NSData,磁盘上的映像大小为75 KB,但当我试图从该资产获取NSData时,它返回的NSData大小非常大,我的问题是“如何从映像返回75 KB的数据而不是更大的数据”

我的代码:

ALAssetRepresentation* representation = [asset defaultRepresentation];
CGFloat scale  = 1;
UIImage* image = [UIImage imageWithCGImage:[representation fullResolutionImage]
                                             scale:scale orientation:orientation];
NSData *data = UIImagePNGRepresentation(image);

iOS 9更新:在iOS 9及更高版本中,您应该在
PHImageManager
上使用
requestImageDataForAsset:options:resultHandler:
,因为以下代码使用了不推荐使用的方法


你看过课堂参考资料中的“”部分了吗

ALAssetRepresentation *representation = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);

// add error checking here
NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *sourceData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];

iOS 9更新:在iOS 9及更高版本中,您应该在
PHImageManager
上使用
requestImageDataForAsset:options:resultHandler:
,因为以下代码使用了不推荐使用的方法


你看过课堂参考资料中的“”部分了吗

ALAssetRepresentation *representation = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);

// add error checking here
NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *sourceData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];

也许你想要JPEG格式而不是PNG格式。你是如何得到75KB的?也许你想要JPEG格式而不是PNG格式。你是如何得到75KB的?感谢Aaron对这种方法的帮助和警告;这是一个非常好的记忆方法。但如果使用此方法,图像将失去方向。(无论方向如何,每个图像都是横向的)。我正试图找到一种方法,但到目前为止还没有结果感谢亚伦对这种方法的帮助和警告;这是一个非常好的记忆方法。但如果使用此方法,图像将失去方向。(无论方向如何,每个图像都是横向的)。我正在努力想办法,但到目前为止没有结果