I have a method that needs to be parsed through a bunch of large PNG images pixel by pixel (PNG - 600x600 pixels each). It seems to work fine on Simulator, but on the device (iPad) I get EXC_BAD_ACCESS in some copy function of the internal memory. Size seems to be the culprit, because if I try it on smaller images, everything seems to work. Here is a description of the meat associated with memory.
+ (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); free(rawData);
When I run this on a bunch of images, it runs 12 times and then twitches, and on the simulator this is not a problem. Do you have any ideas?
memory iphone ipad cgcontext
toastie
source share