博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios 调用相册 及 相册显示中文
阅读量:6257 次
发布时间:2019-06-22

本文共 3434 字,大约阅读时间需要 11 分钟。

hot3.png

  相册显示中文

  在info.plist中添加

 
CFBundleAllowMixedLocalizations
    
//先要设置代理@interface BlogViewController : UIViewController 
{    AMapLocationManager * locationManager;}@end-(IBAction)chooseImage:(id)sender {        UIActionSheet *sheet;    //判断是否支持相机    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])    {        sheet  = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"拍照",@"从相册选择", nil];            } else {        sheet = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"取消" otherButtonTitles:@"从相册选择", nil];         }        sheet.tag = 255;        [sheet showInView:self.view];    }-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{    if (actionSheet.tag == 255) {                NSUInteger sourceType = 0;                // 判断是否支持相机        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {                        switch (buttonIndex) {                case 0:                    // 取消                    return;                case 1:                    // 相机                    sourceType = UIImagePickerControllerSourceTypeCamera;                    break;                                    case 2:                    // 相册                    sourceType = UIImagePickerControllerSourceTypePhotoLibrary;                    break;            }        }        else {            if (buttonIndex == 0) {                                return;            } else {                sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;            }        }              UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];                imagePickerController.delegate = self;                imagePickerController.allowsEditing = YES;                imagePickerController.sourceType = sourceType;                [self presentViewController:imagePickerController animated:YES completion:^{}];            }}#pragma mark - image picker delegte- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{    [picker dismissViewControllerAnimated:YES completion:^{}];        UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];      // 保存图片至本地,方法见下文    [self saveImage:image withName:@"currentImage.png"];        NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"currentImage.png"];        UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath];       // isFullScreen = NO;    [self.imageView setImage:savedImage];        self.imageView.tag = 100;    }- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{    [self dismissViewControllerAnimated:YES completion:^{}];}#pragma mark - 保存图片至沙盒- (void) saveImage:(UIImage *)currentImage withName:(NSString *)imageName{    NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);    // 获取沙盒目录        NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];    // 将图片写入文件    [imageData writeToFile:fullPath atomically:NO];}

参考资料

相册和拍照调用方法 请看转载文章

转载于:https://my.oschina.net/u/554046/blog/624874

你可能感兴趣的文章
1_NAT模式和桥接模式下的网络配置
查看>>
EF架构~为EF DbContext生成的实体添加注释(T5模板应用)
查看>>
【转】VLAN原理详解
查看>>
python --- json模块和pickle模块详解
查看>>
idea中artifacts、facets、modules是什么意思?
查看>>
FUCKED-BUG之临时对象的生死
查看>>
SP2 PRIME1 - Prime Generator
查看>>
创建和编辑 crontab 文件
查看>>
钉钉发消息
查看>>
20172309_《程序设计与数据结构(下)》_课堂测试修改报告。
查看>>
(二十九)方法调用之解析
查看>>
Springboot文件上传与下载
查看>>
Activity与Fragment数据传递之Fragment从Activity获取数据 分类: ...
查看>>
记一次小的51CTO聚会
查看>>
架構設計_案例說明_by 高老師
查看>>
VR內容開發(PAGE-2)
查看>>
飞舞的蝴蝶
查看>>
Linux环境下C语言模拟内存负载测试
查看>>
专栏《轻松玩转ELK海量可视化日志分析系统》已完结【附代码下载】
查看>>
新手IT人员,如何找到适合自己专业书籍的6个问题?
查看>>