从 [UIImage] 创建电影,Swift [英] create movie from [UIImage], Swift

查看:27
本文介绍了从 [UIImage] 创建电影,Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 导出 [UIImage] 作为电影,但它全部在 ObjectiveC 中,我无法为 Swift 弄清楚.

I've found export [UIImage] as movie, but its all in ObjectiveC and I can't figure it out for Swift.

我需要从 [UIImage] 创建一个视频

I need to create a video from [UIImage]

根据上面的链接处理 Zoul 的回答.第 1 部分)联系作家

Working on Zoul's answer from above link. part 1) Wire the writer

到目前为止我有:

let paths = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
    let documentsURL = paths[0] as! NSURL
    let videoWriter:AVAssetWriter = AVAssetWriter(URL: documentsURL, fileType: AVFileTypeQuickTimeMovie, error: nil)

    var videoSettings: NSDictionary = NSDictionary(

我无法弄清楚他的正确 Swift 版本

I can't figure out the correct Swift version of his

NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt:640], AVVideoWidthKey,
[NSNumber numberWithInt:480], AVVideoHeightKey,
nil];

<小时>

推荐答案

构造一个 Dictionary 文字很简单:

Constructing a Dictionary literal is straightforward:

import AVFoundation

let videoSettings = [
    AVVideoCodecKey: AVVideoCodecH264,
    AVVideoWidthKey: 640,
    AVVideoHeightKey: 480
]

至于其他所有内容,我鼓励您通读 Apple 的Swift 编程语言首先建立基础,而不是依赖于恰好涵盖您想要做的事情的 SO 或教程.正如他们所说,教人钓鱼".

As for everything else, I would encourage you to read through Apple's The Swift Programming Language to establish fundamentals first, rather than relying on SO or tutorials that happen to cover what you want to do. "Teach a man to fish", as they say.

这篇关于从 [UIImage] 创建电影,Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆