Ios 像视频一样显示一系列图像?

Ios 像视频一样显示一系列图像?,ios,animation,image-processing,uiimageview,uiimage,Ios,Animation,Image Processing,Uiimageview,Uiimage,我正在iOS上试验图像处理算法。我有一个带有图像的资产目录test\u frame1测试框架100(等等),我在上面做一些处理 除此之外,我需要按顺序显示图像,就像它们是视频的帧一样 我想到的第一件事是在几毫秒的延迟后依次更改UIImage的图像。我正在异步地做这件事。代码如下: let imageShowQueue = dispatch_queue_create("com.grigoryptashko.ImageShowQueue", DISPATCH_QUEUE_SE

我正在iOS上试验图像处理算法。我有一个带有图像的资产目录
test\u frame1
<代码>测试框架100(等等),我在上面做一些处理

除此之外,我需要按顺序显示图像,就像它们是视频的帧一样

我想到的第一件事是在几毫秒的延迟后依次更改
UIImage
的图像。我正在异步地做这件事。代码如下:

    let imageShowQueue = dispatch_queue_create("com.grigoryptashko.ImageShowQueue",
        DISPATCH_QUEUE_SERIAL)
    let frameShowDelay = Int64(0.2 * Double(NSEC_PER_SEC)) // show images with 200 ms delay, but it doesn't actually work this way
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {
        var dTime = dispatch_time(DISPATCH_TIME_NOW, frameShowDelay)
        for i in 1...1000 {
            dispatch_after(dTime, self.imageShowQueue) {
                dispatch_async(dispatch_get_main_queue()) {
                    NSLog("test_frame\((i % 100) + 1)")
                    self.imgView.image = UIImage(named: "test_frame\((i % 100) + 1)")
                    self.imgView.setNeedsDisplay()
                }
            }

            dTime = dispatch_time(dTime, frameShowDelay)
        }
    }
它实际上可以工作,但FPS很快就会变得太低,比如1 FPS甚至更慢。有没有其他方法可以做到这一点


也许,有某种方式我不知道。例如,最近我学习了
Accelerate
框架和
Apple Metal
。还有其他想法吗?

试试这个,更改数组中的图像并编译项目,在这个部分设置de时间间隔

animationImageView.animationDuration = 0.5;

听起来你想要一个基于图像的动画。以下是您将要做的:

视图中加载

self.<name of the UIImageView you want to animate>.animationImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:@"Image Name"],
                                     [UIImage imageNamed:@"Image Name"],
                                     [UIImage imageNamed:@"Image Name"],
                                     [UIImage imageNamed:@"Image Name"],
                                     [UIImage imageNamed:@"Image Name"],
                                     [UIImage imageNamed:@"Image Name"],
                                     [UIImage imageNamed:@"Image Name"],
                                     [UIImage imageNamed:@"Image Name"],nil];
                      /* Do this until you have all the images in the array */
self.<name of the UIImageView you want to animate>.animationDuration = 1.0f;
self.<name of the UIImageView you want to animate>.animationRepeatCount = 1;

使用
UIImage
上的
animatedImageNamed:
可以更直接地完成此操作。看看这个:

UIImage *animatingImage = [UIImage animatedImageNamed:@"test_frame_" duration:1.0];
UIImageView *anImageView = [[UIImageView alloc] initWithImage:animatingImage];
UIImage *animatingImage = [UIImage animatedImageNamed:@"test_frame_" duration:1.0];
UIImageView *anImageView = [[UIImageView alloc] initWithImage:animatingImage];