保存到相册时iPhone捕获图像应用程序崩溃

保存到相册时iPhone捕获图像应用程序崩溃,iphone,uiimage,capture,Iphone,Uiimage,Capture,在我的应用程序中,我制作了一个屏幕截图: UIImage *viewImage = [UIImage imageWithCGImage:UIGetScreenImage()]; CGRect cropRect = CGRectMake(0, 0, 320, 440); CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], cropRect); viewImage = [UIImage imag

在我的应用程序中,我制作了一个屏幕截图:

 UIImage *viewImage = [UIImage imageWithCGImage:UIGetScreenImage()];
 CGRect cropRect = CGRectMake(0, 0, 320, 440);
 CGImageRef imageRef = CGImageCreateWithImageInRect([viewImage CGImage], cropRect);
    viewImage = [UIImage imageWithCGImage:imageRef];
 CGImageRelease(imageRef);
    captureImage = [[UIImage alloc] init];
 captureImage = viewImage;
然后我想将其保存到相册中:

UIImageWriteToSavedPhotosAlbum(anImage, self, @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), nil);

- (void)   savedPhotoImage:(UIImage *)image
didFinishSavingWithError:(NSError *)error
           contextInfo:(void *)contextInfo
 {    
 NSString *themessage = @"This image has been saved to your Photos album. Tap to  continue.";
NSString *errorTitle = @"Image saved.";
 if (error) {
     themessage = [error localizedDescription];
errorTitle = @"error";
 }
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:errorTitle
                                                 message:themessage
                                                delegate:nil
                                       cancelButtonTitle:@"OK"
                                       otherButtonTitles:nil];
[alert show];
[alert release];
}
保存到相册时,应用程序崩溃。 捕获的图像是好的,我可以成功地上传和显示它。 我还试着从内存中加载一张图片并将其保存到相册中,效果也不错

我猜我在处理我的图像的时候做错了什么。。 有什么想法吗


谢谢

你能检查一下权限吗?如果禁用,下次将不会显示警报。

因为这个问题太老了,我想展示一种更现代的方式来做你想做的事情。 此代码可用于捕获屏幕:

- (UIImage *) getScreenShot
{
    UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
    CGRect rect = [keyWindow bounds];
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    [keyWindow.layer renderInContext:context];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}
下面是保存图像的代码:

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
{
    PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:screenShot];
} 
completionHandler:^(BOOL success, NSError *error) 
{
    if (success) 
    {
        NSLog(@"successfully saved");
    }
    else 
    {
        NSLog(@"error saving to photos: %@", error);
    }
}];}

你有没有坏的访问错误,或者什么?不幸的是,我不能在实际设备上测试,我只能从客户那里得到反馈。此外,UIGetScreenImage函数在模拟器中不可用。