UIImageJPEGRepresentation占用大量内存

iEn*_*eer 4 objective-c uiimage ios

我试图找出这个问题,但在做了我在OS或谷歌上发现的所有事情后失败了.问题是,当我转换UIImageNSData使用UIImageJPEGRepresentationUIImagePNGRepresentation它将内存大小增加到30Mb(相信我或不相信).
这是我的代码

myImage= image;
LoginSinglton*loginObj = [LoginSinglton sharedInstance];
NSError *error;
NSData *pngData = UIImageJPEGRepresentation(image, scaleValue); //scaleVale is 1.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory

self.imageCurrentDateAndTime =[self getTimeAndDate];
 self.filePathAndDirectory = [documentsPath stringByAppendingPathComponent:@"Photos Dir"];

NSLog(@"Documents path %@",self.filePathAndDirectory);
if (![[NSFileManager defaultManager] createDirectoryAtPath:self.filePathAndDirectory
                               withIntermediateDirectories:NO
                                                attributes:nil
                                                     error:&error])
{
    NSLog(@"Create directory error: %@", error);
}
self.imageName= [NSString stringWithFormat:@"photo-%@-%@.jpg",loginObj.userWebID,self.imageCurrentDateAndTime];
 NSString *filePath = [self.filePathAndDirectory stringByAppendingPathComponent:self.imageName];

[pngData writeToFile:filePath atomically:YES]; //Write the file
[self writeImageThumbnailToFolder:image];
[self writeImageHomeViewThumbnailToFolder:image];  
Run Code Online (Sandbox Code Playgroud)

我尝试了以下解决方案以及 UIImageJPEGRepresentation - 内存释放问题
1-使用@autoreleasepool
2- done pngData = nil;
但仍面临着记忆问题.

编辑我想我无法传达我的问题.如果UIImageJPEGRepresentation占用大量内存,这是可以的,在保存该图像后,内存应该回到它的早期位置.希望这会对你有所帮助.

Guy*_*gus 8

使用scaleValue小于1的a .即使0.9也会大大减少内存占用,同时将质量损失降至最低.

  • 做到了0.8但没有效果. (3认同)