Ios UIImageJPEG表示不存在';我不能保持比例设置

Ios UIImageJPEG表示不存在';我不能保持比例设置,ios,uiimage,nsdata,Ios,Uiimage,Nsdata,当我以一定的比例使用initWithCGImage,然后使用UIImageJPEGRepresentation从该图像获取数据时,系统似乎没有保留我的比例设置。知道为什么吗 以下是我的代码和日志: ALAssetRepresentation *rep = [asset defaultRepresentation]; CGImageRef iref = [rep fullResolutionImage]; UIImageOrientation orientation = [self orienta

当我以一定的比例使用initWithCGImage,然后使用UIImageJPEGRepresentation从该图像获取数据时,系统似乎没有保留我的比例设置。知道为什么吗

以下是我的代码和日志:

ALAssetRepresentation *rep = [asset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
UIImageOrientation orientation = [self orientationForAsset:asset];

// Scale the image                          
UIImage* scaledImage = [[UIImage alloc] initWithCGImage:iref scale:2. orientation:orientation];
NSLog (@"Scaled image size %@", NSStringFromCGSize(scaledImage.size));

// Get data from image
NSData* scaledImageData = UIImageJPEGRepresentation(scaledImage, 0.8);

//  Check the image size of the data
UIImage* buildedImage = [UIImage imageWithData:scaledImageData];
NSLog (@"Data image size of %@", NSStringFromCGSize (buildedImage.size));
提供日志:

缩放图像大小{19441296}

数据映像大小为{38882592}


这真的很奇怪,因为这两个图像应该完全相同。

你应该使用-[UIImage imageWithData:scale:方法。

我知道jpeg对缩放一无所知。问题是如果我上传缩放图像数据,在服务器上,我得到的图像具有原始大小,而不是缩放大小。如果为
uiimagejpegresentation
指定的值接近1,则会降低图像质量。因此,将其缩小,如
0.2
。我的问题是,当我上载scaledImageData时,服务器会获得原始大小的图像,而不是缩放的图像。我的代码中的BuildImage只是在上传之前检查我的NSData中到底有什么。然后@sage444对你的问题的评论就是你问题的答案。我想是的。。。这意味着我需要创建一个原始比例的图像。然后用我需要的维度构建另一个映像,并从第二个映像发送数据。但我想您需要有一个参数才能将“scale”发送到服务器。因此,您可以使用它将数据转换回图像。