将 .obj 文件数据转换为 NSImage
Converting .obj file data to NSImage
我正在尝试将数据从 .obj 文件转换为 base64 字符串,以便我可以在 NSImageView
中显示 .obj 文件的缩略图预览。
下面是我从本地 url 获取资产并将其转换为 base64 字符串的代码。然后我将其转换为 Data
,然后尝试将其转换为图像。
let fileUrl = Foundation.URL(string: input_string)
let data: NSData? = NSData(contentsOfFile: input_string)
if let fileData = data {
let base64String = fileData.base64EncodedString()
let decodedData = NSData(base64Encoded: base64String, options: NSData.Base64DecodingOptions(rawValue: 0) )
let decodedimage = NSImage(data: decodedData! as Data)
}
我可以看到我正在获取数据集,但 decodedImage
始终为零 - 我猜这与 .obj 图像格式有关,我可能对此了解不够。任何见解/帮助表示赞赏。
编辑:这是一张屏幕截图,显示了 .obj 文件在 Finder 预览中的样子。
OBJ 不是图像格式。它是旧的 3D model format. If you want to convert it to an image you will need to open the file and add it to a SCNScene as a geometry node and then render out the the SCNView 图像并保存该图像。
我正在尝试将数据从 .obj 文件转换为 base64 字符串,以便我可以在 NSImageView
中显示 .obj 文件的缩略图预览。
下面是我从本地 url 获取资产并将其转换为 base64 字符串的代码。然后我将其转换为 Data
,然后尝试将其转换为图像。
let fileUrl = Foundation.URL(string: input_string)
let data: NSData? = NSData(contentsOfFile: input_string)
if let fileData = data {
let base64String = fileData.base64EncodedString()
let decodedData = NSData(base64Encoded: base64String, options: NSData.Base64DecodingOptions(rawValue: 0) )
let decodedimage = NSImage(data: decodedData! as Data)
}
我可以看到我正在获取数据集,但 decodedImage
始终为零 - 我猜这与 .obj 图像格式有关,我可能对此了解不够。任何见解/帮助表示赞赏。
编辑:这是一张屏幕截图,显示了 .obj 文件在 Finder 预览中的样子。
OBJ 不是图像格式。它是旧的 3D model format. If you want to convert it to an image you will need to open the file and add it to a SCNScene as a geometry node and then render out the the SCNView 图像并保存该图像。