0

Say I would like to have a 10x10 image filled with different RGB colours

How do I create the Core Graphics bitmap context, and draw each pixel in?

I have searched but cannot find any resources on writing to a Core Graphics bitmap context.

How create UIImage from bytes? says what I need to do but does not say how to do it

Benj
  • 736
  • 7
  • 21

1 Answers1

1

You don't even need to draw to a bitmap context

let width = 10
let height = 10
  • A variable of type [UInt8] to store RGB data (call it data for example), where data[0] to data[2] is the first pixels red green blue values between 0-255, data[3] to data[5] is the second pixels red green blue values between 0-255. data.count must equals height * width
  • make a cfdata object from that variable
  • pass that cfdata to cfdataprovider initiliaser
  • pass that cfdataprovider to cgimage initialiser

congratulations you now how a cgimage object with pixel values taken from data

Benj
  • 736
  • 7
  • 21