UIImageHEIC icon indicating copy to clipboard operation
UIImageHEIC copied to clipboard

Transparency

Open barrettj opened this issue 8 years ago • 2 comments

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.

barrettj avatar Jan 26 '18 00:01 barrettj

@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.

timonus avatar Jan 26 '18 04:01 timonus

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

barrettj avatar Jan 26 '18 15:01 barrettj