Iphone 在NSMutable数组中存储UIGetScreenImage()中的图像
我从UIGetScreenImage()获取图像,并直接存储在可变数组中,如:-Iphone 在NSMutable数组中存储UIGetScreenImage()中的图像,iphone,objective-c,Iphone,Objective C,我从UIGetScreenImage()获取图像,并直接存储在可变数组中,如:- image = [UIImage imageWithScreenContents]; [array addObject:image]; [image release]; 我已在计时器中设置了此代码,因此无法使用UIImagePNGRepresentation()将其存储为NSData,因为这会降低性能。我想在一段时间后直接使用此阵列,即在100秒内捕获1000张图像后。当我使用下面的代码时:- UIImage *
image = [UIImage imageWithScreenContents];
[array addObject:image];
[image release];
我已在计时器中设置了此代码,因此无法使用UIImagePNGRepresentation()将其存储为NSData,因为这会降低性能。我想在一段时间后直接使用此阵列,即在100秒内捕获1000张图像后。当我使用下面的代码时:-
UIImage *im = [[UIImage alloc] init];
im = [array objectAtIndex:i];
UIImageWriteToSavedPhotosAlbum(im, nil, nil, nil);**
应用程序崩溃。
我不想在计时器中使用UIImagePNG或JPGRepresentation(),因为这会降低性能
我的问题是如何使用此数组,以便将其转换为图像。
如果有人有与此相关的想法,请与我分享。您不需要在第一个代码示例中发布此图像<代码>[UIImage imageWithScreenContents]返回自动删除的对象
1. UIImage *im = [[UIImage alloc] init];
2. im = [array objectAtIndex:i];
3. UIImageWriteToSavedPhotosAlbum(im, nil, nil, nil);
第1行分配并初始化一个新的UIImage对象,该对象永远不会被释放,因为您覆盖了第2行上的指针。每次迭代都会泄漏一个UIImage,甚至不需要初始化/分配新对象
UIImageWriteToSavedPhotosAlbum([array objectAtIndex:i], nil, nil, nil);
应该很好用
还请注意Carl Norum关于释放自动释放对象的回答。同样正确-我甚至没有读下去看到这一点。此错误导致内存泄漏,而不是OP看到的崩溃,但值得一试+1.UIImageWriteToSavedPhotosAlbum([array objectAtIndex:i],nil,nil,nil);也会崩溃。实际上数组包含什么?有没有办法从这个数组中获取图像-Das SujyanarayanThanks回答。[UIImage imageWithScreenContents]返回图像,在此函数中,CGImageRef取自UIGetScreenImage(),并将其释放。所以,这就是为什么图像是发布im的第一个代码。
1. UIImage *im = [[UIImage alloc] init];
2. im = [array objectAtIndex:i];
3. UIImageWriteToSavedPhotosAlbum(im, nil, nil, nil);