简体   繁体   English

将拍摄的图像保存在照片库中

[英]Save taken image in photo library

I have coded this program to save image while picking the uiimage but i need to code to save the image in UIImagePickerControllerSourceTypePhotoLibrary while capturing the 我已经对该程序进行了编码,以在拾取uiimage时保存图像,但是我需要编码以在捕获UIimagePickerControllerSourceSourcePhotoPhotoLibrary时保存图像
image by camera only. 仅由相机拍摄。

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if([info objectForKey:@"UIImagePickerControllerOriginalImage"])
{
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
    {
        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
        UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
        PhotoViewController *photoVC=[[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
        photoVC.photoImage=image;
        photoVC.photoDelegate=self;
        [self.navigationController pushViewController:photoVC animated:YES];
    }


}

I think this will help you. 我认为这会对您有所帮助。 please try this one. 请试试这个。

This is code for taking a image using camera : 这是使用相机拍摄图像的代码:

 UIImagePickerController *myImagePickerController = [[UIImagePickerController alloc]init];
 myImagePickerController.delegate = self;
 UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
 if (YES == [UIImagePickerController isSourceTypeAvailable:sourceType])
    {
        myImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self.view addSubview:myImagePickerController.view];
    }
    else
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Warning !!" message:@"Camera is not available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    }

This code for saving image on Photo Library : 此代码用于在照片库中保存图像:

  UIImage *img = [UIImage imageNamed:@"image.png"]; // This is your after taking photo
  UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);


  - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
   {
if (error != NULL)
    {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:[[error localizedDescription] capitalizedString]  delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
     }
  else 
     {


    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sucesses !!" message:@"Your image has been saved sucessefully."  delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
            [alert setTag:100];
    [alert release];
  }

}

If you want to save picked image to photo library then use/write UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo); 如果要将选择的图像保存到照片库中,请使用/编写UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo); function in didFinishPickingImage didFinishPickingImage函数

such like, 像这样

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo
{    
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    [picker dismissModalViewControllerAnimated:NO];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{    if([info objectForKey:@"UIImagePickerControllerOriginalImage"])
{

   UIImage *tmpimage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
    {
        if ((picker.sourceType=UIImagePickerControllerSourceTypeCamera)) {
            UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
            UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
        }
        PhotoViewController *photoVC=[[PhotoViewController alloc]initWithNibName:@"PhotoViewController" bundle:nil];
        photoVC.photoImage=tmpimage;
        photoVC.photoDelegate=self;
        [self.navigationController pushViewController:photoVC animated:YES];
    }


}
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用照片框架将图像保存到照片库 - Save image to photo library using photo framework 如何保存拍摄的照片 - How to save taken photo 只有在相机拍摄时才将图像保存到照片库,如果从照片库中选择则不能 - Save images to photo library ONLY if they are taken by camera and not if chosen from photo library 将使用 UIImagePickerController 拍摄的图像以 HEIC 格式保存到照片胶卷中 - Save image taken with UIImagePickerController to photo roll in HEIC format 是否可以检查图像是由相机拍摄的还是由JavaScript从照片库上传的? - Is it possible to check if an image is taken by camera or uploaded from photo library by JavaScript? 如何检测照片库中的图像是由iPhone相机拍摄还是导入 - how to detect if image from photo library was taken by iPhone camera or imported 将代表图像的NSMutableData保存到iPhone照片库 - Save NSMutableData representing an image to the iPhone photo library 哪个最好保存照片库中的图像? - which is best to save image in the photo library? 如何将图像从 imageView 保存到照片库? - How to save image from imageView to Photo Library? 将图像从iOS WebApp保存到照片库 - Save image from iOS WebApp to Photo Library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM