Iphone UIImage上下文编辑导致SIGABRT/EXC\u访问错误

Iphone UIImage上下文编辑导致SIGABRT/EXC\u访问错误,iphone,multithreading,uiimage,editing,Iphone,Multithreading,Uiimage,Editing,我的代码中有一个非常奇怪的行为。我想在UIGraphicsImageContext中编辑一些图形内容。有时有效,有时无效。我正在将图像处理函数分离到一个新线程,如下所示: -(void)process:(SEL)function withObject:(id)sender { UIActivityIndicatorView *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndica

我的代码中有一个非常奇怪的行为。我想在UIGraphicsImageContext中编辑一些图形内容。有时有效,有时无效。我正在将图像处理函数分离到一个新线程,如下所示:

-(void)process:(SEL)function withObject:(id)sender {
UIActivityIndicatorView  *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
av.frame = CGRectMake(round((self.view.frame.size.width - 50) / 2), 
                      round((self.view.frame.size.height - 50) / 2), 50, 50);
av.tag  = kActivityTag;
[self.view addSubview:av];
[av startAnimating];
[self enableControls:NO];
[NSThread detachNewThreadSelector:function toTarget:self withObject:sender];
在此函数之一调用process函数之前,如下所示:

-(void)imageColorTintChanged:(id)sender {
[self process:@selector(tint:) withObject:sender];}

-(void)tint:(id)sender {
@synchronized(image) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    float f       = ((UISlider *)sender).value;
    NSInteger tag = ((UISlider *)sender).tag;
    if (tag == 0) {
        redTint = f;
    } else if (tag == 1) {
        greenTint = f;
    } else if (tag == 2) {
        blueTint = f;
    }
    previewImage = [ImageUtil colorizeImage:image color:[UIColor colorWithRed:redTint green:greenTint blue:blueTint alpha:1.0]];
    [imageView setImage:previewImage];
    [self processDidFinish];
    [pool release];
}}
最后,我的图形编辑从新线程开始:

+ (UIImage *)colorizeImage:(UIImage *)baseImage color:(UIColor *)theColor {
if (baseImage) {
    @synchronized (baseImage) {
        UIGraphicsBeginImageContext(baseImage.size);  // CRASH!!

        CGContextRef ctx = UIGraphicsGetCurrentContext();
        CGRect area = CGRectMake(0.0f, 0.0f, baseImage.size.width, baseImage.size.height);

        CGContextTranslateCTM(ctx, 0.0, baseImage.size.height);
        CGContextScaleCTM(ctx, 1.0, -1.0);    

        [theColor set];
        CGContextFillRect(ctx, area);

        CGContextSetBlendMode(ctx, kCGBlendModeMultiply);

        CGContextDrawImage(ctx, area, baseImage.CGImage);

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return newImage;
    }
}
return baseImage;
大多数情况下,它在这一行崩溃:

UIGraphicsBeginImageContext(baseImage.size)

可能是什么?穿线的东西? 提前谢谢

编辑:

嗯,我在仪器上做了一个活动监视器测试,出于某种原因,它说没有内存泄漏,但经过一些图像处理后,实际内存使用量上升到53MB,然后崩溃。是否可能只是一些“我使用了太多内存”错误?

来自,关于
UIGraphicsBeginImageContext()

您应该仅从应用程序的主线程调用此函数

您需要在此处创建一个
CGBitmapContext

从,关于
UIGraphicsBeginImageContext()

您应该仅从应用程序的主线程调用此函数

您需要在此处创建
CGBitmapContext