iPhone / iPad上的CGBitmapContextCreate [英] CGBitmapContextCreate on the iPhone/iPad

查看:103
本文介绍了iPhone / iPad上的CGBitmapContextCreate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种方法需要逐像素地解析一堆大的PNG图像(PNG每个600x600像素)。它似乎在模拟器上工作得很好,但在设备(iPad)上,我在某些内部存储器复制功能中获得了EXC_BAD_ACCESS。似乎尺寸是罪魁祸首,因为如果我在较小的图像上尝试它,一切似乎都有效。以下是与方法相关的内存方法。

I have a method that needs to parse through a bunch of large PNG images pixel by pixel (the PNGs are 600x600 pixels each). It seems to work great on the Simulator, but on the device (iPad), i get an EXC_BAD_ACCESS in some internal memory copying function. It seems the size is the culprit because if I try it on smaller images, everything seems to work. Here's the memory related meat of method below.

+ (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次然后缩小,同时打开它运行的模拟器没问题。你们有什么想法吗?

When I run this on a bunch of images, it runs 12 times and then craps out, while on the simulator it runs no problem. Do you guys have any ideas?

推荐答案

转到产品 - >编辑方案 - >启用Zombie对象。在启用Zombie对象之前勾选一个刻度线。现在构建并运行它。它可以为您提供更好的EXC_BAD_ACCES错误的点描述。

Goto Product -> Edit Schemes -> Enable Zombie objects. Put a tick mark before Enable Zombie objects. Now build and run it. It can give you better and to the point description for EXC_BAD_ACCES error.

这篇关于iPhone / iPad上的CGBitmapContextCreate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆