Core Image: From CIImage to Metal and Beyond · Save Core Image Output | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5428948-core-image-from-ciimage-to-metal-and-beyond/lessons/5

I am puzzled about what the writeHEIFRepresentation is supposed to be doing. The Apple doc says “Renders the image and exports the resulting image data as a file in HEIF format.” (The doc also says the writeHEIFRepresentation function call returns True if successful but there is no return value.)

So I assumed that there would be an “.heif” file written to my Shared Playground Data? No heif file is written. Instead the Playground console displays a large imageProperties dictionary. Why are we bothering with this step?

1 Like

HI @ahoeltje

You assumed correctly—an HEIF file should have been written to that directory—and in fact it was in the beta that I wrote it in. I’m not sure what the issue is here. It could be that it’s a playground issue and it works fine in a real app.

According to the documentation, this should return a boolean that signifies success or failure. Since this is not the case, I suspect there is a bug. It’s worth trying it in a real app, but otherwise, it looks like it might be a bug.

Sorry for not being able to provide a more definitive answer

sam

Oddly, on my end, it spits out a black file for both jpeg, and an empty image for heic; this happens in my code, as well as the playground (updated to use my username as the directory). I am wondering if this is just part of the “magic” of playgrounds, or a kernel issue that needs to be patched by Apple?

Thanks for investigating @exsangus. Did you try it on a device? It used to be that there were things that never really worked on the simulator—especially those involving the GPU. That happens much less these days, but it could be that this falls into that category.

I’m sorry not to be of more help…

sam

I didn’t try saving the file in the photos library, because that was way more effort than I wanted to put into it for a playground lesson… :smile:

I just ran it on the playground and tried saving to a directory on my Mac. The image showed up fine in the preview window, it just didn’t write it properly. I am betting that it is a GPU hardware issue, as I have had to rewrite code a little bit to get some of the examples from the RW Metal book to not crash when running them on the Mac target (while iPhone target ran fine).

@exsangus Do you still have issues with this?

In the latest official release of Xcode this is still a problem, however, it looks like Apple has fixed the bug in Xcode 12.0 Beta 1.

Update: Still working in Beta 2.