how to save UIImagePicker image with a specific name

泪湿孤枕 提交于 2019-12-04 14:21:24

问题


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 possibilities to change the image size eg. from 100 x 100 pixels to 50 x 50 pixels

thanks


回答1:


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.



来源:https://stackoverflow.com/questions/2046108/how-to-save-uiimagepicker-image-with-a-specific-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!