【发布时间】:2015-02-23 04:34:11
【问题描述】:
所以我正在尝试制作一个可以让用户更改 UIImage 的颜色的应用程序,因为我正在使用我发现的这个功能
- (UIImage *)imageWithTintColor:(UIColor *)color fraction:(CGFloat)fraction
{
if (color)
{
UIImage *image;
if ([UIScreen instancesRespondToSelector:@selector(scale)])
{
UIGraphicsBeginImageContextWithOptions([self size], NO, 0.f);
}
else
{
UIGraphicsBeginImageContext([self size]);
}
CGRect rect = CGRectZero;
rect.size = [self size];
[color set];
UIRectFill(rect);
[self drawInRect:rect blendMode:kCGBlendModeDestinationIn alpha:1.0];
if (fraction > 0.0)
{
[self drawInRect:rect blendMode:kCGBlendModeSourceAtop alpha:fraction];
}
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
return self;
}
一切正常,但 CG 栅格数据在内存中增长
【问题讨论】:
-
图片大小是多少?
-
大约 200-300kb,我看到那些 200、300 kb...但最后 BAAM 30MB
-
图片的尺寸是多少? 3000x2000 像素?我还假设这是在 iPad 模拟器上?
-
图像是 1240x1240,是的,它是 iPad,但我可以向您展示 iPhone 的规格,仍然没有变化,我听说过有关放置 @autoreleasepool 的信息,但对我不起作用...或者我不确定在哪里设置它
-
问题可能出在其他方面:UIImageView 占用大量内存在 iPad 大屏幕上显示大图像
标签: ios xcode memory-management core-graphics