【发布时间】:2011-02-08 23:47:10
【问题描述】:
在 iPhone 应用程序上,我需要通过邮件发送最大大小为 300Ko 的 jpg(我没有 mail.app 可以具有的最大大小,但这是另一个问题)。为此,我正在尝试降低质量,直到获得低于 300Ko 的图像。
为了获得300Ko下给我的jpg质量(compressionLevel)的好值,我做了如下循环。 它正在工作,但是每次执行循环时,尽管有“[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);
}
关于如何摆脱它或为什么会发生的任何想法? 谢谢
【问题讨论】:
标签: iphone memory uiimage uiimagejpegrepresentation