我可以将多少张图像加载到 NSMutableArray 中以在 ImageView 中显示?
我需要加载 150 个 JPEG 图像,每个图像 100Kb,但是 加载 110 个 JPEG(每个 60Kb)后,我收到内存警告。
我的数组是:
imagesSet = [[NSMutableArray alloc] init];
图像是这样加载的:
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%d", IMAGE_PREFIX, i] ofType:IMAGE_FORMAT];
NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
[imagesSet addObject:[UIImage imageWithData:imageData]];
?
show:imageView.image = [imagesSet objectAtIndex:[number intValue]];
内存不够吗 或者我做错了什么?
I need to load 150 JPEG images that are 100Kb each, but
I get a memory warnings after loading 110 JPEGs at 60Kb each.
My array is:
imagesSet = [[NSMutableArray alloc] init];
and images are loaded like this:
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@%d", IMAGE_PREFIX, i] ofType:IMAGE_FORMAT];
NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
[imagesSet addObject:[UIImage imageWithData:imageData]];
and
show:imageView.image = [imagesSet objectAtIndex:[number intValue]];
Is there not enough memory? Or am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,您已经超出了移动设备的内存。请记住,JPEG 图像在加载后将被解码。要计算单个图像所需的实际内存量,您可以在使用 UIImageView 时运行以下公式:(宽度 * 4) * 高度。
You are exceeding the memory of a mobile device by far. Remember that a JPEG image will get decoded after being loaded. To calculate the actual amount of memory needed for a single image, you may run this formula: (width * 4) * height when using an UIImageView.