4

我有一个应用程序将各种过滤器应用于图像。它在 iOS 5 上运行良好,但在 6 上崩溃。下面是它崩溃的示例:

CGImageRef inImage = self.CGImage;
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage)); 
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef); 

int length = CFDataGetLength(m_DataRef);

for (int i=0; i<length; i+=4)
{
    if(filter == filterCurve){

    int r = i;
    int g = i+1;
    int b = i+2;

    int red = m_PixelBuf[r];
    int green = m_PixelBuf[g];
    int blue = m_PixelBuf[b];

    m_PixelBuf[r] = SAFECOLOR(red); //    <==== EXC_BAD_ACCESS (code = 2)
    m_PixelBuf[g] = SAFECOLOR(green);
    m_PixelBuf[b] = SAFECOLOR(blue);
   }
}

当我尝试将值分配回m_PixelBuf. 有人知道为什么会这样吗?iOS 6 中的什么会导致这种情况?

4

2 回答 2

5

这解决了问题:http ://www.iphonedevsdk.com/forum/iphone-sdk-development/108072-exc_bad_access-in-ios-6-but-not-in-ios-5.html

在 iOS 6 中,如果要直接操作数据的字节,则需要使用CFDataCreateMutableCopy()(而不是CGDataProviderCopyData()),然后使用 (而CFDataGetMutableBytePtr()不是)。CFDataGetBytePtr()

于 2012-09-21T05:17:12.960 回答
0

This is the url where you find new class which works with ios 6:https://github.com/kypselia/ios-image-filters/blob/6ef9a937a931f32dd0b7b5e5bbdca6cce2f690dc/Classes/ImageFilter.m

于 2012-11-20T06:25:09.117 回答