I have an UIImage that I want to edit (say, make every second row of pixels black). Now I am aware of the functions that extract PNG or JPEG data from the image, but that’s raw data and I have no idea how the png/jpeg files work. Is there a way I can extract the colour data from each pixel into an array? And then make a new UIImage using the data from the array?
Share
Create a CGBitmapContext and draw the UIImage’s CGImage into it. Clobber pixel bytes as appropriate, then create a new CGImage (and UIImage, if desired) from the bytes.
The main reason to do this is that CGImage supports a wide variety of pixel formats, which would not be fun for you to try to support if you were to try to work with whatever format a given CGImage had happened to have been created with.