swift - 快速上的图像

标签 swift command-line

我正在使用 Swift 2.0 在 Xcode 中使用命令行工具。我是这门语言的新手,我主要使用 c#。在 C# 中,当您想要将图像从硬盘驱动器加载到您的程序时,您可以简单地使用 Image.ImageFromFileName(file_adress),然后将其另存为位图并对其进行处理。我在 swift 中搜索了类似的东西,但什么也没找到。有办法这样做吗? 再说一次,我不只是使用命令行工具为 OS X 或 iOS 编写应用程序。

最佳答案

如果您只想将任何格式的图像转换为 .bmp,您可以使用 Automator,无需编程。

但是如果你想用 Swift 来做:

import Cocoa

let image = NSImage(byReferencingFile: "/path/to/image.jpg")!
let bitmapRep = image.representations[0] as! NSBitmapImageRep
let data = bitmapRep.representationUsingType(.NSBMPFileType, properties: [:])!

data.writeToFile("/path/to/output.bmp", atomically: true)

关于swift - 快速上的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37090584/

相关文章:

python - 收到 'can' t 用 python 包在 '__main__' 中找到 '<packageName>' 模块

swift - 在 Swift 中重构代码

Swift 3 隐式解包选项导致错误的字符串插值

ios10 swift3.0 Alamofire上传图片出现错误

Python 命令行脚本 : file/directory autocompletion on user input

pdf - 批量打印在文本文件中列出的 PDF 文件

windows - 将多个命令的结果存储在一个文件中

linux - 将 FTP 内容下载到另一台服务器的更好方法

ios - Swift:架构 i386 的 undefined symbol : "_OBJC_CLASS_$_CGColor"

objective-c - 在文件夹引用模式下添加文件时,Xcode 找不到头文件