gpt4 book ai didi

iphone - CFDataGetBytePtr期间应用崩溃

转载 作者:行者123 更新时间:2023-12-03 17:39:54 24 4
gpt4 key购买 nike

当我调用CFDataGetBytePtr时,我的应用程序崩溃(偶尔-通常在运行8到10次后崩溃)。基本上,我想从图像中复制像素字节并在可以进行进一步操作时存储在缓冲区中。是因为我没有发布m_PixelBuf吗?还是复制数据的错误方法?

+ (int**) UIImage2GrayInt:(UIImage*)inImage
{
CGImageRef cgImage = inImage.CGImage;
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(cgImage));
UInt8 *m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
int m_iH = CGImageGetHeight(cgImage);
int m_iW = CGImageGetWidth(cgImage);
//short* m_inDataGrey = malloc(sizeof(short)*(m_iW*m_iH));

int**piData = [self initVal:m_iH:m_iW];
//Convert GreyScale and copy data
int iStep,jStep;


for (int i = 0; i < m_iH; i++)
{
iStep = i*m_iW*4;
//iStepGrey = i*m_iW;
for (int j = 0; j < m_iW; j++)
{
jStep = j*4;
piData[i][j] = ((double)m_PixelBuf[iStep + jStep] + (double)m_PixelBuf[iStep + jStep +1] + (double)m_PixelBuf[iStep + jStep +2])/3.0;
}
}

m_PixelBuf = NULL;
CFRelease(m_DataRef);
return piData;
}

这是崩溃日志
1.  0 MyApp 0x000606ae testflight_backtrace + 238
2. 1 MyApp 0x00061398 TFSignalHandler + 264
3. 2 libsystem_c.dylib 0x328b87ec _sigtramp + 48
4. 3 MyApp 0x00046fa4 +[clsGlobalHelper UIImage2GrayInt:] (clsGlobalHelper.m:276)
5. 4 MyApp 0x00046fa4 +[clsGlobalHelper UIImage2GrayInt:] (clsGlobalHelper.m:276)
6. 5 MyApp 0x00046d40 +[clsGlobalHelper resizeImageAvg:::] (clsGlobalHelper.m:212)
7. 6 MyApp 0x00036fd2 -[clsNewPhoto ProcessSelectedFace] (clsFirstViewController.m:618)
8. 7 MyApp 0x000354ae -[clsNewPhoto btnSelectGender:] (clsFirstViewController.m:309)
9. 8 CoreFoundation 0x354063fc -[NSObject performSelector:withObject:withObject:] + 52

这是 initval的代码
+(int**) initVal:(int) Nr:( int) Nc 
{
int ** p;
p = calloc(Nr,sizeof(int*));

for(int i = 0; i < Nr; i++)
{
p[i] = calloc(Nc,sizeof(int));

}
return p;
}

最佳答案

this问题的答案帮助我解决了问题。仍然不知道CFDataGetBytePtr是什么问题,但至少我有前进的解决方案。

关于iphone - CFDataGetBytePtr期间应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13042816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com