上传头像(照相机、图片库)
来源:互联网 发布:安卓可视化编程 编辑:程序博客网 时间:2024/05/01 23:56
#pragma mark - 上传头像
- (IBAction)btnUploadHeadClicked:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
[actionSheet addButtonWithTitle:@"拍照"];
[actionSheet addButtonWithTitle:@"从手机相册选择"];
// 同时添加一个取消按钮
[actionSheet addButtonWithTitle:@"取消"];
// 将取消按钮的index设置成我们刚添加的那个按钮,这样在delegate中就可以知道是那个按钮
actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
[actionSheet showInView:self.view];
[actionSheet release];
}
#pragma mark - 判断设备是否有摄像头
- (BOOL) isCameraAvailable
{
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}
#pragma mark - UIActionSheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.editing = YES;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
if (buttonIndex == 0)//照相机
{
if ([self isCameraAvailable]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}else{
[PublicMethod showMBProgressHUD:@"该设备没有摄像头" andWhereView:self.view hiddenTime:kHiddenTime];
}
}
if (buttonIndex == 1)
{
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
if (buttonIndex == 2)
{
}
[imagePicker release];
}
#pragma mark - UIImagePicker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [[info objectForKey:UIImagePickerControllerEditedImage] retain];
[self performSelector:@selector(saveImage:) withObject:image afterDelay:0.5];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
#pragma mark -
- (void)saveImage:(UIImage *)image
{
imgVHead.image = image;
}
@end
- (IBAction)btnUploadHeadClicked:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil, nil];
[actionSheet addButtonWithTitle:@"拍照"];
[actionSheet addButtonWithTitle:@"从手机相册选择"];
// 同时添加一个取消按钮
[actionSheet addButtonWithTitle:@"取消"];
// 将取消按钮的index设置成我们刚添加的那个按钮,这样在delegate中就可以知道是那个按钮
actionSheet.destructiveButtonIndex = actionSheet.numberOfButtons - 1;
[actionSheet showInView:self.view];
[actionSheet release];
}
#pragma mark - 判断设备是否有摄像头
- (BOOL) isCameraAvailable
{
return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}
#pragma mark - UIActionSheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.editing = YES;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
if (buttonIndex == 0)//照相机
{
if ([self isCameraAvailable]) {
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}else{
[PublicMethod showMBProgressHUD:@"该设备没有摄像头" andWhereView:self.view hiddenTime:kHiddenTime];
}
}
if (buttonIndex == 1)
{
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
if (buttonIndex == 2)
{
}
[imagePicker release];
}
#pragma mark - UIImagePicker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [[info objectForKey:UIImagePickerControllerEditedImage] retain];
[self performSelector:@selector(saveImage:) withObject:image afterDelay:0.5];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
#pragma mark -
- (void)saveImage:(UIImage *)image
{
imgVHead.image = image;
}
@end
- 上传头像(照相机、图片库)
- 照相机和图片库(1)
- 照相机和图片库(2)
- IOS 使用照相机和图片库
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像 (转)
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS 实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS---头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- iOS实现头像选取(照相或者图片库)、大小等比缩放、生成圆形头像
- 调用照相机与图片库并实现保存图片到图片库
- strange COM problem under CE 6
- ZestFinance:前谷歌CIO创立的机器学习+大数据分析公司
- 根据字数自动换行的UILabel
- POJ 2632 Crashing Robots
- 30大最有影响力的Web设计与开发英文博客
- 上传头像(照相机、图片库)
- C++ union的用法
- 为sourceinsight添加makefile、kconfig、*.S文件支持
- hdu 2647 Reward(拓扑排序+邻接表)
- Tiled Map Editor(二)
- C++学习——函数(2)
- tomcat虚拟路径配
- Server JBoss v4.2 at localhost was unable to start within 50 seconds.
- linux之stat函数解析