ios - 如何将imageWithContentsOfFile用于动画中使用的图像数组?

标签 ios uiimage

这是我目前拥有的:

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。

我可以使用单个图像,但不能使用整个数组:
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];
}

任何帮助是极大的赞赏!谢谢!

最佳答案

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

关于ios - 如何将imageWithContentsOfFile用于动画中使用的图像数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7886959/

相关文章:

ios - 如何检查 Xcode Asset Catalog 中是否存在图像?

ios - 如何找到 UIImage 瓶颈

ios - 我如何在 iOS 中实现 Payeezy 定期基本付款?

ios - SKTexture 和 UIImage 的缩放属性

ios - 如何使用swift将录像保存到文档目录?

iphone - 即使新版本已获批准并准备销售,AppStore 仍会下载旧版本

swift - 在 UIImageView 之上的 Swift 上将蒙版层作为 UIImage

ios - 将视网膜图像转换为视频 : "CGContextScaleCTM: invalid context 0x0. This is a serious error."

ios - 从 Windows 移动到 mac 后,M1 上的 Flutter : GoogleMapsBase & Flutter. h 未发现错误

ios - 如何在 Objective-C 中为 pin mapview 中的文本添加事件处理程序?