我正在制作一个应用程序,就像电影播放器,但不是显示视频,而是在图像帧中放映电影。滑块用于向前和向后移动“电影”,如果释放,则“电影”会自动播放到一个章节。 我通过在滑块的每个值更改上使用UIImageView
并更改image
属性来实现此目的。一段时间后,由于内存警告,应用程序崩溃。我不能使用UIImage的动画,因为我想通过清理滑块来控制位置(即可见图像/帧)。 因此,我有一个ImageManager类,它在init中加载数组中字符串中的所有图像名称(每个图像总共大约150kb)。UIImageView由于内存警告而崩溃,试图加载大量图像
- (id) initWithCanvas:(UIImageView*) canvasView{
self = [super init];
if (self) {
totalImages = 1500;
self.canvas = canvasView;
self.images = [[NSMutableArray alloc] init];
for (int i=0; i<totalImages; i++){
[self.images addObject:[NSString stringWithFormat:@"frame_%04d.jpg", i]];
i = i + 4; // I use this to skip 4 frames
}
previewsImageIndex = -1;
[self setImageAtPosition:0];
}
return self;
}
然后我有一个在其上找到当前图像名称和构建从图像名称一个UIImage,并把它设置为UIImageView的
- (void) setImageAtPosition:(CGFloat)percentage{
currentImage = nil;
int position = percentage * [self.images count];
if (position != previewsImageIndex){
previewsImageIndex = position;
NSLog(@"Got image:%d at percentage: %f", position, percentage);
if (position < [self.images count]){
self.canvas.image = nil;
currentImage = [UIImage imageNamed:[self.images objectAtIndex:position]];
[self.canvas setImage:currentImage];
currentImage = nil;
//[currentImage release];
}
}
}
即使UISlider的值变化发射功能我将currentImage和canvas.image设置为零,应用程序崩溃后不久。我不明白我在哪里有内存泄漏。另外,我使用ARC编码,因此没有发布。
有没有其他更好的方式来做到这一点,除了有一个UIImage视图?我想要逐帧查看功能,并且MPMoviePlayer或AVPlayer不能进行细粒度的清理。
不要使用'imageNamed',因为它会缓存你的图片。 –
请显示'currentImage'的声明。 –
@MarcusAdams UIImage * currentImage;但它是''imageNamed'做了坏的东西 –