我有一个方法,需要解析通过一堆大PNG图像逐像素(每个PNGs是600x600像素)。它似乎在模拟器上效果很好,但在设备(iPad)上,我在某些内部存储器复制功能中获得了EXC_BAD_ACCESS。看起来大小是罪魁祸首,因为如果我在较小的图像上尝试它,一切似乎都奏效。下面的方法是记忆相关的肉类。CGBitmapContextCreate在iPhone/iPad上
+ (CGRect) getAlphaBoundsForUImage: (UIImage*) image
{
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
memset(rawData,0,height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
/* non-memory related stuff */
free(rawData);
当我在一堆图像上运行它时,它运行12次然后在模拟器上运行时没有问题。你们有什么想法吗?