代码之家  ›  专栏  ›  技术社区  ›  Mc.Lover

使用uiImageWrite将图像保存到相机胶卷以保存照片集

  •  4
  • Mc.Lover  · 技术社区  · 15 年前

    在用户用相机拍摄照片后,我试图用按钮将照片保存到相机卷上,但我不知道为什么我的照片不能保存在照片库中!!

    这是我的代码:

    -(IBAction)savePhoto{
    
        UIImageWriteToSavedPhotosAlbum(img.image,nil, nil, nil);
    
    }
    
    -(IBAction)takePic {
    
        ipc = [[UIImagePickerController alloc]init];
        ipc.delegate = self;
        ipc.sourceType = UIImagePickerControllerSourceTypeCamera; 
        [self presentModalViewController:ipc animated:YES];
    
    }
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
        img.image = [[info objectForKey:UIImagePickerControllerOriginalImage]retain];
        [[picker parentViewController]dismissModalViewControllerAnimated:YES];
        [picker release];   
    }
    

    变量名 ipc UIImagePickerController img UIIMageView .

    我的问题是什么?

    1 回复  |  直到 9 年前
        1
  •  4
  •   zoul    15 年前

    首先确保你打电话来 savePhoto . 然后您可以添加断言以检查图像是否为零:

    - (IBAction) savePhoto {
        NSParameterAssert(img.image);
        UIImageWriteToSavedPhotosAlbum(img.image, nil, nil, nil);
    }