invalidname

Creating CGImage from BGRA data (but A=0 pix are opaq white)

Jul 10th, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.16 KB | None | 0 0
  1. // this is producing an image with a white background, rather than clear. wtf.
  2. // chromaKeyCFData is BGRA, with background pixels having A==0.
  3. // cgImage is source image (from a PNG) that I'm punching green pixels out of.
  4. // colorSpace is cgImage.colorSpace! (ie, force unwrapped)
  5. guard let chromaKeyDataProvider = CGDataProvider(data: chromaKeyCFData),
  6.     let chromaKeyCGImage = CGImage(width: cgImage.width,
  7.                                    height: cgImage.height,
  8.                                    bitsPerComponent: cgImage.bitsPerComponent,
  9.                                    bitsPerPixel: cgImage.bitsPerPixel,
  10.                                    bytesPerRow: cgImage.bytesPerRow,
  11.                                    space: colorSpace,
  12.                                    bitmapInfo: cgImage.bitmapInfo,
  13.                                    provider: chromaKeyDataProvider,
  14.                                    decode: nil,
  15.                                    shouldInterpolate: false,
  16.                                    intent: CGColorRenderingIntent.defaultIntent) else { return nil }
  17. let chromaKeyImage = UIImage(cgImage: chromaKeyCGImage)
  18. return chromaKeyImage
Advertisement
Add Comment
Please, Sign In to add comment