I just want to know
how to set a particular pixel’s colour to red?
suppose x =37 y=54 and i want to change this pixel’s colour to red.
I have no clue how to do it.
I have got the values of points around a particular object into an array of pixels using marching square algo.
I just want to know how to set a particular pixel’s colour to red?
Share
You cannot change the pixels of an existing
CGImage. You have to create a newCGImagewith the pixel changed. These are the steps:CGBitmapContextwithCGBitmapContextCreate.CGImageinto it usingCGContextDrawImage.CGContextSetFillColorWithColorandCGContextFillRect.CGImageusingCGBitmapContextCreateImage.Instead of using
CGContextSetFillColorWithColorandCGContextFillRect, you could tweak the bitmap data directly after retrieving a pointer to it withCGBitmapContextGetData. That would be faster if you’re going to do it a lot.Also, if you’re going to do it a lot, you will want to create the bitmap context and draw the original image into it just once, and keep the bitmap context around for diddling. But creating the new
CGImagefrom the bitmap context may be a bottleneck.