gpt4 book ai didi

ios - 像视频一样显示一系列图像?

转载 作者:行者123 更新时间:2023-12-01 18:49:01 25 4
gpt4 key购买 nike

我正在 iOS 上试验图像处理算法。我有一个带有图片的 Assets 目录 test_frame1 ... test_frame100 (等等)我做一些处理。

除其他外,我需要按顺序显示图像,就好像它们是视频的帧一样。

我首先想到的是顺序更改 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 . Ant 其他想法?

最佳答案

听起来你想要一个基于图像的动画。这是你要做的:

在您的 viewDidLoad

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;

然后你使用 [<name of the UIImageView you want to animate> startAnimating];你想让动画开始吗? animationDuration 的号码和 animationRepeatCount可以更改为您希望它们成为的值。 Here是 Apple Docs 的链接。

对于 Swift 开发:
<name of the UIImageView you want to animate>.animationImages = [
UIImage(named: "Image Name")!,
UIImage(named: "Image Name")!,
UIImage(named: "Image Name")!,
UIImage(named: "Image Name")!,
UIImage(named: "Image Name")!,
UIImage(named: "Image Name")!,
UIImage(named: "Image Name")!,
UIImage(named: "Image Name")!
]
/* Do this until you have all the images in the array */
<name of the UIImageView you want to animate>.animationDuration = 1.0
<name of the UIImageView you want to animate>.animationRepeatCount = 1

关于ios - 像视频一样显示一系列图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32634692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com