如何使用特定名称保存UIImagePicker图像 [英] how to save UIImagePicker image with a specific name

查看:182
本文介绍了如何使用特定名称保存UIImagePicker图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用UIPickerController从iphone捕获图像,然后以编程方式使用特定名称保存图像,以及稍后调用图像(通过使用名称),是否有可能更改图像大小,例如。从100 x 100像素到50 x 50像素

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

谢谢

推荐答案

以下代码片段将图像保存到文件中:

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.

这篇关于如何使用特定名称保存UIImagePicker图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆