2009-01-16 90 views

回答

15

我将这些方法添加到我的视图的控制器类。他们保存照片,然后弹出一个警告框告诉用户它是否成功。

- (void)savePhotoOfView:(UIView *)view 
{ 
    UIGraphicsBeginImageContext(view.bounds.size); 
    [view drawRect:view.bounds]; 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    UIImageWriteToSavedPhotosAlbum(image, 
            self, 
            @selector(savedPhotoImage:didFinishSavingWithError:contextInfo:), 
            NULL); 
} 

- (void) savedPhotoImage:(UIImage *)image 
    didFinishSavingWithError:(NSError *)error 
       contextInfo:(void *)contextInfo 
{  
    NSString *message = @"This image has been saved to your Photos album"; 
    if (error) { 
     message = [error localizedDescription]; 
    } 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil 
                message:message 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 
+0

此代码保存白色图像(空白图像)进入我的照片明矾u能请指导我,我做什么错误,我有复制过去的,上面的代码到我的项目,但不工作:( – 2011-12-14 12:34:51

相关问题