当我从相机 ( )Received Memory Warning
拍照时,我的应用程序崩溃并显示“ ”。UIImagePickerController
当我遇到崩溃时的场景:如果我的设备上正在运行其他应用程序(2 个或更多),我会遇到崩溃,并且如果在我启动我的应用程序之前只有一个其他应用程序正在运行或没有其他应用程序在运行,那么就没有崩溃了。
仅当我从相机中拍照时才会发生此崩溃,但是当我从照片库中选择图片时根本没有崩溃。
我正在使用 Xcode 4.3.2 并且正在使用 ARC。
谁可以帮我这个事?
这是我正在使用的代码
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex: (NSInteger)buttonIndex
{
if (buttonIndex < 2)
{
if([UIImagePickerController isSourceTypeAvailable:buttonIndex==0?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
[ipc setDelegate:(id<UIImagePickerControllerDelegate,UINavigationControllerDelegate>) self];
[ipc setSourceType:buttonIndex==0?UIImagePickerControllerSourceTypeCamera:UIImagePickerControllerSourceTypePhotoLibrary];
if (buttonIndex == 0)
{
[ipc setAllowsEditing:NO];
}
[ipc setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]];
[self presentModalViewController:ipc animated:YES];
}
else
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Action Alert" message:@"Camera is not available in this device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissModalViewControllerAnimated:YES];
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
if (!image) image = [info objectForKey:UIImagePickerControllerOriginalImage];
[NSThread detachNewThreadSelector:@selector(scallImage:) toTarget:self withObject:image];
}
-(void) scallImage:(UIImage *) image
{
CGSize newSize = CGSizeMake(320, 480);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
image=nil;
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *cImage = [UIImageJPEGRepresentation(newImage, 0.5) base64EncodedString];
[ImageButton setBackgroundImage:newImage forState:UIControlStateNormal];
[ImageButton setHidden:NO];
//[profileImageButton setBackgroundImage:newImage forState:UIControlStateNormal];
newImage=nil;
}
我的代码有什么问题吗?