gpt4 book ai didi

ios - CFRelease 导致 iPad 应用程序崩溃

转载 作者:行者123 更新时间:2023-11-29 13:07:49 27 4
gpt4 key购买 nike

我正在尝试合并四张图片以使其成为一张 uiimage。但是当我要执行 CFRelease 时,它​​崩溃了。如果我不这样做,就会导致内存泄漏和崩溃。如何解决?

请参阅下面的代码。

    referenceView.frame = CGRectMake(0, 0, 1024, 768);
referenceView.hidden = NO;

[self.view insertSubview:referenceView belowSubview:selfView];

imgView1.image = delegate.imageCroped;
imgView2.image = [UIImage imageNamed:@"videobg.png"];
imgView3.image = [UIImage imageNamed:@"videochar.png"];;
imgView4.image = smileView.image;

imgView1.frame = CGRectMake(456, 311, delegate.imageCroped.size.width-30.8, delegate.imageCroped.size.height-40);
imgView2.frame = CGRectMake(0, 0, 1024, 768);
imgView3.frame = CGRectMake(392, 187, imgView3.image.size.width, imgView3.image.size.height);
imgView4.frame = CGRectMake((smileView.frame.origin.x-((smileView.frame.origin.x > 530) ? 30 : 15)), (smileView.frame.origin.y+((smileView.frame.origin.y <= 307) ? 95 : 50)), smileView.frame.size.width, smileView.frame.size.height);

[referenceView addSubview:imgView1];
[referenceView addSubview:imgView2];
[referenceView addSubview:imgView3];
[referenceView addSubview:imgView4];

UIGraphicsBeginImageContext(referenceView.bounds.size);
[referenceView.layer renderInContext:UIGraphicsGetCurrentContext()];
CGImageRef finalImage = ( CGImageRef)(UIGraphicsGetImageFromCurrentImageContext());
UIGraphicsEndImageContext();

[referenceView removeFromSuperview];
[imgView1 removeFromSuperview];
[imgView2 removeFromSuperview];
[imgView3 removeFromSuperview];
[imgView4 removeFromSuperview];

UIImage *resizedImage = [UIImage imageWithCGImage:finalImage];

CFRelease(finalImage);

return resizedImage;

}
@catch (NSException *exception) {

}

我收到以下错误。我该如何解决这个问题?我的项目在 ARC 中。

* -[UIImage _cfTypeID]: message sent to deallocated instance 0x1e88dce0

最佳答案

UIGraphicsGetImageFromCurrentImageContext() 返回 UIImage *,而不是 CGImageRef。而且您不拥有生成的 UIImage,因此您不想释放它(或 CFRelease() 它)。

尝试:

UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();

相反。

关于ios - CFRelease 导致 iPad 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18194371/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com