#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];
}