从相机、相册获取照片或图片


#pragma mark - 相机相册处理UIPickerControllerDelegate

- (IBAction)cameraImage:(id)sender {

    [newsText resignFirstResponder];


    //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库

    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;

    if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {

        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    }

//    sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //图片库

//    sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; //保存的相片

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化

    picker.delegate = self;

    picker.allowsEditing = YES;//设置可编辑

    picker.sourceType = sourceType;

    [self presentViewController:picker animated:YES completion:nil];

//    [self presentModalViewController:picker animated:YES];//进入照相界面

}


- (IBAction)ablumImage:(id)sender {

    [newsText resignFirstResponder];


    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化

    picker.delegate = self;

    picker.allowsEditing = YES;//设置可编辑

    picker.sourceType = sourceType;

    [self presentViewController:picker animated:YES completion:nil];

}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

    UIImage *aImage = [info objectForKey:UIImagePickerControllerOriginalImage];

    UIImage *bigImage = [self imageWithImageSimple:aImage scaledToSize:CGSizeMake(800.0, 800.0)];

    

    NSString *imageName = [Functions getNowInterval];

    imageName = [NSString stringWithFormat:@"%@.jpg",imageName];

    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];


    [self saveImage:bigImage withName:fullPath];

    //处理上传数据

    [postArray addObject:fullPath];

    [self showImages];

    

    [self dismissViewControllerAnimated:YES completion:nil];

    [newsText resignFirstResponder];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值