Expand description
CoreGraphics — turning a CGImage into bytes, and bytes into a PNG.
AppKit’s NSBitmapImageRep does both of these on the Mac, and the macOS
capture paths still use it: those renders are compared byte-for-byte against
a Swift reference, and swapping the pixel plumbing underneath them would
invalidate that. CoreGraphics and ImageIO are the same API on every Apple
platform, so this is what the iOS paths use instead.
The two are not interchangeable — a bitmap context cannot hold non-premultiplied alpha — but that does not matter: each platform is only ever compared against a reference rendered the same way it was.
Functions§
- capture_
layer ⚠ - Rasterise a
CALayerinto a tightly packed RGBA8 buffer. - cgimage_
to_ ⚠rgba - Draw a
CGImageinto a tightly packed RGBA8 buffer. - rgba_
to_ ⚠cgimage - Build a
CGImagefrom tightly packed RGBA8 bytes. Caller owns the result. - write_
png - Write RGBA8 bytes to a PNG file.