imageWithContentsOfFile

imageWithContentsOfFile

本文介绍了如何将 imageWithContentsOfFile 用于动画中使用的图像数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我目前拥有的:

NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:21];

 for(int count = 1; count <= 21; count++)
{
    NSString *fileName = [NSString stringWithFormat:@"dance2_%03d.jpg", count];
    UIImage  *frame    = [UIImage imageNamed:fileName];
    [images addObject:frame];
}

UIImage imageNamed 给我带来了一些内存问题,我想切换到 imageWithContentsOfFile.

UIImage imageNamed is causing me some memory issues and I would like to switch to imageWithContentsOfFile.

我可以使用单个图像,但不能使用整个数组:

I can make it work with a single image, but not the whole array:

NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:21];

for(int count = 1; count <= 21; count++)
{
    NSString *fileName = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/dance2_001.jpg"];
    UIImage  *frame    = [UIImage imageWithContentsOfFile:fileName];
    [images addObject:frame];
}

非常感谢任何帮助!谢谢!

Any help is greatly appreciated! Thanks!

推荐答案

for(int i = 1; i <= 21; i++)
    {
        [images addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"dance2_%03d", i] ofType:@"jpg"]]];
    }

这篇关于如何将 imageWithContentsOfFile 用于动画中使用的图像数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 21:51