图片存储在相册


- (void)openImagePickerController:(UIImagePickerControllerSourceType)type

{

//打开相机

   UIImagePickerControllerSourceTypeCamera;

// 如果想自己写一个图片选择控制器,得利用AssetsLibrary.framework,利用这个框架可以获得手机上的所有相册图片

    // UIImagePickerControllerSourceTypePhotoLibrary 图片数> UIImagePickerControllerSourceTypeSavedPhotosAlbum 图片数

   UIImagePickerControllerSourceTypePhotoLibrary;



    if (![UIImagePickerControllerisSourceTypeAvailable:type])return;

    

    UIImagePickerController *ipc = [[UIImagePickerControlleralloc]init];

    ipc.sourceType = type;

    ipc.delegate = self;

    [selfpresentViewController:ipcanimated:YEScompletion:nil];

}


#pragma mark - UIImagePickerControllerDelegate

/**

 * UIImagePickerController选择完图片后就调用(拍照完毕或者选择相册图片完毕)

 */

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    [picker dismissViewControllerAnimated:YEScompletion:nil];

    

    // info中就包含了选择的图片

    UIImage *image = info[UIImagePickerControllerOriginalImage];

    

    // 添加图片到photosView

    [self.photosViewaddPhoto:image];

}




- (void)save{

    UIGraphicsBeginImageContext(self.bounds.size);

    

    //view渲染到位图上下文

    [self.layerrenderInContext:UIGraphicsGetCurrentContext()];

    

    //获取图片

    UIImage *captureImg =UIGraphicsGetImageFromCurrentImageContext();

    

    //结束位图的编辑

    UIGraphicsEndImageContext();

    

    //返回

    UIImageWriteToSavedPhotosAlbum(captureImg,self, @selector(image:didFinishSavingWithError:contextInfo:),nil);


}



//图片保存成功的提示

- (void)image: (UIImage *)image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo{

    if (!error) {

        UIAlertView * alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"图片保存成功"delegate:selfcancelButtonTitle:nilotherButtonTitles:@"确认",nil];

        [alert show];

    }

  

}


你可能感兴趣的:(图片存储在相册)