Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparency #5

Open
barrettj opened this issue Jan 26, 2018 · 2 comments
Open

Transparency #5

barrettj opened this issue Jan 26, 2018 · 2 comments

Comments

@barrettj
Copy link

If your UIImage has transparency you end up with a black background despite HEIC being supposed to support transparency (and the docs saying the default bg color when the format doesn't support transparency is supposed to be white) - any ideas on how to fix this? I've played around for a couple hours and haven't come up with anything.

@timonus
Copy link
Owner

timonus commented Jan 26, 2018

@barrettj can you paste a code snippet of how exactly you're doing this? If you're using the UIGraphicsImageGenerator category you need to specify that the image shouldn't be opaque.

@barrettj
Copy link
Author

I was using tj_UIImageHEICRepresentation (and custom versions of the method where I was trying different CGImageDest commands to get it to keep the transparency without success)

I did get it working, but not with the CGImageDestinationCreateWithData family. I had to use AVFoundation code like the following:

        guard let cgImage = cgImage else {
           return nil
        }
        
        let ciImage = CIImage.init(cgImage: cgImage)
        
        let context = CIContext()
        let heicData = context.heifRepresentation(of: ciImage, format: kCIFormatABGR8, colorSpace: ciImage.colorSpace!, options: [:])
        
        return heicData

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants