I am working on a paint application and want to build the undo manager. I store the pixel co-ordinate value of each location where the user draws but I also want to store the old pixel colour of the point where the user has drawn so that I can undo it to appropriate colour. But I am unable to do so. Can anybody help.
Here is the code I am currently using to get the pixel colour:
UIGraphicsBeginImageContext(self.tempDrawImage.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
int bpr = CGBitmapContextGetBytesPerRow(context);
unsigned char * data = CGBitmapContextGetData(context);
if (data!=NULL)
{
int offset = bpr*(lastPoint.y)+ 4*(lastPoint.x);
NSLog(@"Red : %d",data[offset+0]);
NSLog(@"Green : %d",data[offset+1]);
NSLog(@"Blue : %d",data[offset+2]);
}