let cgimage:CGImage let data = cgimage.dataProvider?.data let bytes = CFDataGetBytePtr(data)! let bytesPerPixel = cgimage.bitsPerPixel / cgimage.bitsPerComponent for y in 0 ..< cgimage.height { for x in 0 ..< cgimage.width { let offset = (y * cgimage.bytesPerRow) + (x * bytesPerPixel) let b = bytes[offset] let g = bytes[offset + 1] let r = bytes[offset + 2] } }