i´m using the AVAssetImageGenerator to get images from a movieclip without playing it before. Now i´ve got a question how to set up variables in the loop of a handler? Is it possible? I´m getting this error message and have no idea what does that mean. (google> no results).
"Variable is not assignable (missing __block type specifier)"
So i have to ask the pro´s here. Here´s the code. I want to save or return my generated imageData, so i can delete the "setImage" message within that following handler.
UIImage* thumbImg = [[UIImage alloc] init];
AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error)
{
if (result != AVAssetImageGeneratorSucceeded)
{
NSLog(@"couldn't generate thumbnail, error:%@", error);
}
[button setImage:[UIImage imageWithCGImage:im] forState:UIControlStateNormal];
thumbImg = [[UIImage imageWithCGImage:im] retain]开发者_如何学JAVA;
[generator release];
};
Would be great to learn about that. Thanks for your time.
1st of all it seems you don't need to init your thumbImg when its declared - UIImage object created in that line will be overwritten in block and will leak. Just init it with nil value.
Actual problem in your code is that variable you're going to change in block should be declared with __block specifier (as error message says). So your 1s line should be
__block UIImage* thumbImg = nil;
精彩评论