我正在尝试反转和图像,我也需要重置 alpha 计数,但是当我尝试这样做时它会给出一个错误的访问错误(在最后一行崩溃)。什么不能访问数据数组?此方法适用于以前的 iOS 版本。
CGImageRef img;
img =image.CGImage;
CFDataRef dataref=CopyImagePixels(img);
UInt8 *data=(UInt8 *)CFDataGetBytePtr(dataref);
int length=CFDataGetLength(dataref);
for(int index=0;index<length;index+=4){
int alphaCount = data[index+0];
int redCount = data[index+1];
int greenCount = data[index+2];
int blueCount = data[index+3];
int average = (int)roundf(0.2*redCount + 0.71*greenCount+ 0.07*blueCount);
alphaCount = average;
if (alphaCount < 0) alphaCount = 0;
if (alphaCount>255) alphaCount =255;
data[index+0] = (Byte) alphaCount; <-----WHERE IT GIVES EXEC BAD ACCESS
....}