【发布时间】:2010-07-14 10:30:20
【问题描述】:
我想展示一个带有负片图像和正常图像的动画。 首先,调用 getPhoto 方法,用户可以从库中获取图像或使用相机拍摄。
当动画运行时,我希望能够将图像设置为新图像,但随后应用程序崩溃了。
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *negative = [self convertImageToNegative:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
imageView.animationImages = [NSArray arrayWithObjects: negative,[info objectForKey:@"UIImagePickerControllerOriginalImage"],nil];
imageView.animationDuration = 60.0; // seconds
imageView.animationRepeatCount = 1; // 0 = loops forever
[imageView startAnimating];
[negative release];
}
- (UIImage *)convertImageToNegative:(UIImage *)image{
UIGraphicsBeginImageContext(image.size);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeDifference);
CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(),[UIColor whiteColor].CGColor);
CGContextFillRect(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, image.size.width, image.size.height));
UIImage *returnImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return returnImage;
}
Instruments - CPU Sampler 显示使用率为 100%。 我怎样才能防止这种情况发生?
【问题讨论】:
-
请格式化您的代码以提高可读性。代码行之间的换行会很有帮助。
-
“应用程序崩溃”出现什么错误?
-
With:wait_fences:未能收到回复:10004003 程序收到信号:“EXC_BAD_ACCESS”。
-
只是一个猜测,但你的代码是线程化的吗?
-
不,穿这个更好吗?
标签: iphone colors crash uiimage