选取照片

- (IBAction)takePhoto:(id)sender {

UIActionSheet*actionSheetPhoto = [[UIActionSheetalloc]initWithTitle:nil

delegate:self

cancelButtonTitle:@"取消"

destructiveButtonTitle:nil

otherButtonTitles:@"拍照",@"从手机相片选择",nil];

[actionSheetPhotoshowInView:self.view];

}

# pragma mark UIActionSheet Delegate

- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

if(buttonIndex == actionSheet.cancelButtonIndex){

return;

}

elseif(buttonIndex ==1){

//从相册中选取照片

[selfselectPhotoFromAlbum];

}

else{

//先判断一下设备有没有摄像头

if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

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

picker.delegate=self;

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

//设置picker支持相机功能

picker.sourceType=UIImagePickerControllerSourceTypeCamera;

//进入照相界面

[selfpresentViewController:pickeranimated:YEScompletion:^{

}];

}

else{

[TSMessageshowNotificationInViewController:selftitle:@"您的设备不支持摄像头"subtitle:@""type:TSMessageNotificationTypeWarning];

}

}

}

//从相册中选择图片

-(void)selectPhotoFromAlbum{

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

picker.delegate=self;

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

picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

[selfpresentViewController:pickeranimated:YEScompletion:^{

}];

}

#pragma mark - UIImagePickerControllerDelegate

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

UIImage*image= [infoobjectForKey:UIImagePickerControllerEditedImage];

[pickerdismissViewControllerAnimated:YES

completion:^{

if(image) {

[photoArrayaddObject:image];

[selfshowPhoto];

}

}];

}

- (NSString*)updateImageToServer:(UIImage*)photoImage

{

NSData*imageData =UIImageJPEGRepresentation(photoImage,1);

imageData=UIImageJPEGRepresentation(photoImage,0.01);

NSString*exName=@"";

NSString*Base64Str=@"";

exName=@"jpg";

Base64Str= [Base64stringByEncodingData:imageData];

returnBase64Str;

}

你可能感兴趣的:(选取照片)