Hi, can someone give me a starting example of how to write an openexr file into disk? I tried the following toy example to write a 2-by-2 checker-box:
import ModelIO
var floatData = UnsafeMutableBufferPointer<Float32>.allocate(capacity: 4)
floatData[0] = Float32(0.99)
floatData[1] = Float32(0.0)
floatData[2] = Float32(0.0)
floatData[3] = Float32(0.99)
var floatBuffer = Data(buffer: floatData)
let exrImg = MDLTexture(data: floatBuffer,
topLeftOrigin: true,
name: "output.exr",
dimensions: SIMD2<Int32>(2,2),
rowStride: 2 * MemoryLayout<Float32>.size,
channelCount: 1,
channelEncoding: MDLTextureChannelEncoding.float32,
isCube: false)
let resourcesURL = URL(fileURLWithPath: "/Users/myDirectory", isDirectory: true)
let fileName = resourcesURL.appendingPathComponent(exrImgTest.name)
if(exrImg.write(to: fileName)){
print("Success! Image written in disk")
} else {
print("could not write image")
}
When I run this I get thread 1: EXC_BAD_ACCESS (code=1, address=0xf0) pointing to the write method of the MDLTexture. If I change the name to output.png the image is written without a problem.
I guess I am missing something basic here. Moreover, how could I write a multiple channel openEXR image to disk?
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: