How to import RAW Image file data in a swift macOS application using Image I/O?

Basically, long and the short of my problem is I NEED to import the full uncompressed RAW image data (obviously from macOS supported image formats) for a project into an array. Unfortunately all example documentation on Image I/O on the Apple dev website appears to have been written with objective-c in mind. Further to this, even when I try to use the class info documentation to produce this code:

Code Block
func getImages(fileLocation:String) -> Void{
let url = CFURLCreateWithString(kCFAllocatorDefault, fileLocation as CFString, nil)!
let imageSource = CGImageSourceCreateWithURL(url, nil)
}


The image source does not get created and I just get a nil response. Any help would be appreciated or even a bit of a suggestion as to where to look. Please keep in mind as well that this is for a scientific computing system that will need as much data collected by the CMOS sensor that produced the file as possible.

Replies

Do you mean imageSource is nil inside the function or when you change the return type to a CGImageSource? and return the value?
The image file type, is it really supported by macOS?
I'm suspicious of your variable named "fileLocation" that you are shoving directly into the URL. Is your URL being created correctly? The function "CFURLCreateWithFileSystemPath" would be more appropriate.