how to save UIImagePicker image with a specific name

后端 未结 1 732
Happy的楠姐
Happy的楠姐 2021-02-11 06:46

i capture image from iphone using UIPickerController, then how programatically to save it with specific name, and to call the image later (by using the name), is it any possibil

1条回答
  •  感动是毒
    2021-02-11 07:04

    The following code snippet will save the image to a file:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
        UIImage *anImage = [info valueForKey:UIImagePickerControllerOriginalImage];
        NSData *imageData = UIImageJPEGRepresentation(anImage, 1.0);
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *path = [paths objectAtIndex:0];
        NSString *tmpPathToFile = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/specificImagedName.jpg", path]];
    
        if([imageData writeToFile:tmpPathToFile atomically:YES]){
              //Write was successful. 
        }
    }
    

    And then to recall the image from a file:

    NSData *imageData = [NSData dataWithContentsOfFile:tmpPathToFile];
    [UIImage imageWithData:imageData];
    

    Finally, this post has a method available that you can incorporate into your project to resize the image.

    0 讨论(0)
提交回复
热议问题