Yes it was problem with calculating offset. It should obey conditions x >= 0, x <= width , y >=0 and y <= height. offset satisfying above conditions only should pass to pixelValueForData: method. Else it get crashed.
Crash on unsigned char of an image due to bad access
-
09-10-2022 - |
Question
Im trying to get RGB values of an image at particular point. Sometimes it get crashed by bad access.
+ (void)pixelValueForData:(unsigned char*)data
atOffset:(int)offset {
int red = data[offset+1];
int green = data[offset+2];
int blue = data[offset+3];
NSLog(@"offset: %i colors: RGB A %i %i %i ",offset,red,green,blue);
}
offset calculated as
int offset = 4*((width*y)+x);
What should i do to avoid that crash ?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow