开发者

To store images from UIGetScreenImage() in NSMutable Array

I'm getting images from UIGetScreenImage() and storing directly in mutable array like:-

image = [UIImage imageWithScreenContents];
[array addObject:image];
[image release];

I've set this code in timer so I cant use UIImagePNGRepresentation() to store as NSData as it reduces the performance. I want to use this array directly after sometime i.e after capturing 1000 images in 100 seconds. When I use the code below:-

UIImage *im = [[UIImage alloc] init];
im = [array objectAtIndex:i];
UIImageWriteToSavedPhotosAlbum(im, nil, nil, nil);**

the application crashes. And I dont want to use UIImagePNG or JPGRepresentation() in timer as it reduces performance.

My problem is how to use this array so that it is converted into image. If anybody has idea related to it please sh开发者_如何学JAVAare with me.


You don't need to release the image in your first code sample there. [UIImage imageWithScreenContents] returns an autoreleased object.


1. UIImage *im = [[UIImage alloc] init]; 
2. im = [array objectAtIndex:i];
3. UIImageWriteToSavedPhotosAlbum(im, nil, nil, nil);

Line 1 allocates and initializes a new UIImage object, which never gets released since you overwrite the pointer on line 2. You are leaking an UIImage in each iteration, and you don't even need to init/alloc a new object.

UIImageWriteToSavedPhotosAlbum([array objectAtIndex:i], nil, nil, nil);

Should work just fine.

Also note Carl Norum answer about releasing an autoreleased object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜