0

我正在使用 GPU 图像开源框架来实现图像效果。问题是当我尝试在图像上定期应用过滤器时,应用程序会给我一个内存警告然后崩溃。

这是代码:

sourcePicture = [[GPUImagePicture alloc] initWithImage:[self scaleAndRotateImage:sourceImage] smoothlyScaleOutput:YES];

GPUImageGaussianBlurFilter *bright=[[GPUImageGaussianBlurFilter alloc]init];
[bright setBlurSize:1.0];

GPUImageFilter *sepiaFilter = bright;
[bright release];
[sepiaFilter prepareForImageCapture];
[sepiaFilter forceProcessingAtSize:self.m_imageView.image.size]; // This is now needed to make the filter run at the smaller output size
[sourcePicture addTarget:sepiaFilter];
[sourcePicture processImage];

UIImage *sep=[sepiaFilter imageFromCurrentlyProcessedOutput];
self.m_imageView.image=sep;
[sourcePicture release];
[sepiaFilter release];

请帮助我摆脱这个问题。谢谢

4

1 回答 1

0

sepiaFilter没有保留bright,所以它只是一个指向已释放对象的指针。您应该更改它以使其保留对象。

GPUImageFilter *sepiaFilter = [bright retain]; // Now retain count is increased +1

否则,这就是该对象正在发生的事情。

GPUImageGaussianBlurFilter *bright = [[GPUImageGaussianBlurFilter alloc] init]; // New object with retain count 1
[bright setBlurSize:1.0];

GPUImageFilter *sepiaFilter = bright; // Still retain count 1 (not being retained)
[bright release]; // Being released. Retain count = 0.
// At this point both sephiaFilter and bright point to released memory.

[sepiaFilter prepareForImageCapture]; // This is calling messages on a released object.
[sepiaFilter forceProcessingAtSize:self.m_imageView.image.size]; // This is calling messages on a released object.
[sourcePicture addTarget:sepiaFilter]; // This is passing a released object as an argument.
于 2013-01-07T10:36:39.957 回答