我正在使用 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/