我试图通过数值增加/减少一定量的值来修改像素值(每通道 RGBA 8 位)。如何在 Objective-C 或 C 中做到这一点?以下代码每次都会生成“错误:EXC_BAD_ACCESS ”。
// Try to Increase RED by 50
for(int i = 0; i < myLength; i += 4) {
//NSLog prints the values FINE as integers
NSLog(@"(%i/%i/%i)", rawData[i], rawData[i+1], rawData[i+2]);
//But for some reason I cannot do this
rawData[i]+=50;
}
乃至
// Try to set RED to 50
for(int i = 0; i < myLength; i += 4) {
//I cannot even do this...
unsigned char newVal = 50;
rawData[i] = 50;
}
旁注: rawData 是 unsigned char 类型的数据缓冲区