我有一个 iphone 应用程序,它从图像中获取字节并进行一些操作。最后,字节被复制回 UIImage。当我在 3GS 上测试时,它运行良好。没有崩溃。当我的一些朋友在4S上测试时,它以adhoc方式崩溃。我使用 testflight 来捕获崩溃报告并进行符号化。这是它崩溃的代码。我使用了相同的 4s 到 3gs 图像,但再次没有崩溃。有谁知道如何找出根本原因并解决它?
当 UIImage 转换为 CGImageRef 时,它会返回不同的宽度和高度吗?
-(UIImage *) CopyBytesToUIImage:(int*)img
:(int) width
:(int) height
{
//(int*)img was build by extracting bytes from OriginalSourceImage
CGImageRef inImage = OriginalSourceImage.CGImage;
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
UInt8 * m_OutPixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
int iStep,jStep;
for (int i = 0; i < height; i++)
{
iStep = i*width*4;
for (int j = 0; j < width; j++)
{
jStep = j*4;
m_OutPixelBuf[iStep + jStep ] = m_OutPixelBuf[iStep + jStep +1] = m_OutPixelBuf[iStep + jStep +2] = img.arr2D[i][j];
//Test flight shows that it crashes during this assignment.
}
}
CGContextRef ctx = CGBitmapContextCreate(m_OutPixelBuf,
CGImageGetWidth(inImage),
CGImageGetHeight(inImage),
CGImageGetBitsPerComponent(inImage),
CGImageGetBytesPerRow(inImage),
CGImageGetColorSpace(inImage), CGImageGetBitmapInfo(inImage)
);
CGImageRef imageRef = CGBitmapContextCreateImage(ctx);
CGContextRelease(ctx);
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CFRelease(m_DataRef);
m_OutPixelBuf = nil;
return finalImage;
}
这是试飞数据
1. 0 MyApp 0x000cf6ae testflight_backtrace + 238
2. 1 MyApp 0x000d0398 TFSignalHandler + 264
3. 2 libsystem_c.dylib 0x3a63de92 _sigtramp + 42
4. 3 MyApp 0x0009e328 -[clsEditor CopyBytesToUIImage:::] + 176
5. 4 MyApp 0x0009e1c4 -[clsEditor Sketch:] + 596
提前谢谢你。