So I have a CGBitmapContext and I get the pixel at a touchlocation using this
unsigned char* data = CGBitmapContextGetData (offscreenBuffer);
if (data != NULL) {
offset = 4*((self.bounds.size.width*round(coord.y))+round(coord.x));
int alpha = data[offset];
int red = data[offset+1];
int green = data[offset+2];
int blue = data[offset+3];
}
And then I change the pixel colour like below.
data[offset]=255;
data[offset+1]=255;
data[offset+2]=0;
data[offset+3]=0;
My question is how do a get a CGImage back from the modified pixels so that I can update my CGBitmapContext?
Any help will be appreciated, Thanks!
Use CGBitmapContextCreateImage() to generate a new CGImage from your context after modifying the data.
Changes you make to the data returned by CGBitmapContextGetData() should modify the context itself. That's a writable pointer, not a copy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With