我正在尝试反转和图像,我也需要重置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
....}
答案 0 :(得分:0)
原来需要在iOS6中将dataref设置为可变
CFMutableDataRef m_DataRef = CFDataCreateMutableCopy(0, 0, CGDataProviderCopyData(CGImageGetDataProvider(inImage)));