在 iPhone 应用程序上,我需要通过邮件发送最大大小为 300Ko 的 jpg(我没有 mail.app 可以具有的最大大小,但这是另一个问题)。为此,我试图降低质量,直到获得低于 300Ko 的图像。
为了获得好值的质量(compressionLevel)谁给我300Ko以下的jpg,我做了如下循环。它正在工作,但是每次执行循环时,尽管有“[tmpImage release];”,但我的 jpg (700Ko) 原始大小的内存会增加。
float compressionLevel = 1.0f;
int size = 300001;
while (size > 300000) {
UIImage *tmpImage =[[UIImage alloc] initWithContentsOfFile:[self fullDocumentsPathForTheFile:@"imageToAnalyse.jpg"]];
size = [UIImageJPEGRepresentation(tmpImage, compressionLevel) length];
[tmpImage release];
//In the following line, the 0.001f decrement is choose just in order test the increase of the memory
//compressionLevel = compressionLevel - 0.001f;
NSLog(@"Compression: %f",compressionLevel);
}
关于如何摆脱它或为什么会发生的任何想法?谢谢