iOS 10 关于相机拍照和图片单张选取
来源:互联网 发布:java开发restful接口 编辑:程序博客网 时间:2024/05/16 01:42
#import "ViewController.h"
#import "GTMBase64.h"
#import <AssetsLibrary/AssetsLibrary.h>
@interface ViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (nonatomic,strong)UIViewController * parentView;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)photosOrcamrae:(id)sender {
UIAlertController *alertController = [UIAlertControlleralertControllerWithTitle:@"选择"message:nilpreferredStyle: UIAlertControllerStyleActionSheet];
UIAlertAction *deleteAction = [UIAlertActionactionWithTitle:@"拍照"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction *deleteAction){
[selftakePictureClick];
}];
UIAlertAction *archiveAction = [UIAlertActionactionWithTitle:@"相册中选取"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *archiveAction){
[selfpictureBtnClick];
}];
UIAlertAction *cancelAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction *cancelAction){
}];
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
[alertController addAction:archiveAction];
[selfpresentViewController:alertControlleranimated:YEScompletion:nil];
}
//调用相机
- (void)takePictureClick{
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *pic = [[UIImagePickerControlleralloc] init];
pic.sourceType =UIImagePickerControllerSourceTypeCamera;
pic.allowsEditing =YES;
pic.showsCameraControls =YES;
pic.delegate =self;
[selfpresentViewController:picanimated:YEScompletion:nil];
}
}
- (void)image:(UIImage *)image didFinishSavingWithError:
(NSError *)error contextInfo:(void *)contextInfo;
{
// Handle the end of the image write process
if (!error){
NSLog(@"Image written to photo album");
}else{
NSLog(@"Error writing to photo album: %@",
[error localizedDescription]);
}
}
//相册选取图片
- (void)pictureBtnClick{
UIImagePickerController *ipc = [[UIImagePickerControlleralloc] init];
ipc.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
ipc.modalTransitionStyle =UIModalTransitionStyleCoverVertical;
ipc.allowsEditing =YES;
ipc.delegate =self;
[selfpresentViewController:ipcanimated:YEScompletion:nil];
}
#pragma mark - ImagePickerDelegate
-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage =UIGraphicsGetImageFromCurrentImageContext();
return newImage;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//相册和相机拍摄的照片选择都走这个代理
UIImage *image = [infoobjectForKey:@"UIImagePickerControllerEditedImage"];
CGSize imagesize = image.size;
imagesize.height =200;
imagesize.width =200;
UIImage *img = [selfimageWithImage:image scaledToSize:imagesize];
[selfupdateUserHeaderWithImage:img];
[selfdismissViewControllerAnimated:YEScompletion:nil];
}
- (void)updateUserHeaderWithImage:(UIImage *)image {
NSData *imageData =UIImageJPEGRepresentation(image,1.0);
NSString *imageStr = [GTMBase64stringByEncodingData:imageData];
//相机拍摄照片存储照片
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ALAssetsLibrary *library = [[ALAssetsLibraryalloc] init];
[library writeImageToSavedPhotosAlbum:[imageCGImage] orientation:(ALAssetOrientation)[imageimageOrientation] completionBlock:^(NSURL *assetURL,NSError *error){
if (error) {
// error handling
} else {
// success handling
}
}];
}
//这里是选择的照片进行处理
}
@end
个人手写,不喜勿喷,下次发布仿写相册多张选取和相机拍照以后的多张选取
干货才是硬道理
- iOS 10 关于相机拍照和图片单张选取
- 从本地选取相册和相机拍照
- ios自定义拍照界面和选取图片界面总结
- iOS选取图片与拍照保存图片
- Android启动相机拍照、相册选取图片,裁剪图片
- iOS 调用相机拍照和选择图库图片 设置头像
- 调用系统相机拍照,从相册选取图片上传
- iOS调用相机 相册 选取图片
- ios 单张图片上传(从相册或者相机)
- Android图片的选取和拍照
- 图片拍照上传和相册选取
- 关于图片的等比缩放,从相机和照片选取头像,显示圆形头像
- Android 相机拍照和本地图片裁剪
- ios相机和图片
- android打开相册选取图片或打开相机拍照并进行裁剪
- 使用AlertDialog弹窗实现相机拍照或者从图库选取图片显示
- android 调用系统相册选取照片或者打开相机拍照获取图片
- android 调用系统相册选取照片或者打开相机拍照获取图片
- 1-oracle基础知识
- UVA 1515 Pool construction
- 细说数据库高性能架构之路
- 利用jdk自带keytool生成ssl证书,搭建tomcat+https协议
- 安卓界面上一些简单QQ 一键加群,微信号 手机号跳转,可用在app关于我们的界面中
- iOS 10 关于相机拍照和图片单张选取
- python发送邮件
- 微信——获取用户基本信息及openid 、access_token、code
- 关于Java队列的编程
- 如何用JS禁止弹出警告框
- Spring overview
- 慎用class_exists方法
- study_1201_retrofit
- ubuntu 上安装最新的postgresql 9.6版本