- (void)initActionSheet

{

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"我的相册",@"拍照", nil];

actionSheet.tintColor = [UIColor whiteColor];

[actionSheet showInView:self.scrollerViewUpload];

}

#pragma mark - UIActionSheetDelegate

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

if (buttonIndex == 0)

{

UIImagePickerController *PickerController = [[UIImagePickerController alloc] init];

PickerController.delegate = self;

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

}

else if (buttonIndex == 1)

{

DNLog(@"拍照");

UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;

//判断是否有相机

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.delegate = self;

//设置拍照后的图片可被编辑

picker.allowsEditing = YES;

//资源类型为照相机

picker.sourceType = sourceType;

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

}else {

[SVProgressHUD showWithStatus:@"没有照相功能" maskType:SVProgressHUDMaskTypeBlack];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[SVProgressHUD dismiss];

});

DNLog(@"没有照相功能");

}

}

}

#pragma mark - UIImagePickerControllerDelegate

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info

{

UIImage *imageNew =info[UIImagePickerControllerOriginalImage];

//设置image的尺寸

CGSize imagesize = imageNew.size;

imagesize.width = imageNew.size.width * 0.45;

imagesize.height = imageNew.size.height *0.45;

//对图片大小进行压缩--

//    imageNew = [self imageWithImage:imageNew scaledToSize:imagesize];

imageNew  = [AppGlobleReciveInfo imageWithImage:imageNew scaledToSize:imagesize];

NSData *imageData = UIImageJPEGRepresentation(imageNew,0.00001);

_selectImage = [UIImage imageWithData:imageData];

self.TravelCardView.image = _selectImage;

[AppGlobleReciveInfo saveWith:_TravelCardView.image nameStr:TravelCardName];

self.TravelCenterBtn.hidden =YES;

self.TravelLable.hidden = YES;

AppGlobleRecive.isTravelCardUpLoadSuccess = false;

[AppGlobleRecive setBool:AppGlobleRecive.isTravelCardUpLoadSuccess forKey:BoolTravelCardUpLoad];

[[NSNotificationCenter defaultCenter] postNotificationName:@"IsSuccessUpLoadIdCard" object:nil];

[picker dismissViewControllerAnimated:YES completion:nil];

}

/**************** 图片上传 ****************/

+(void)uploadImageWithRequest:(NSString *)requestStr fromImage:(UIImage *)image completionHandler:(completionHandler )completionHandler

{

AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];

NSURL * url = [NSURL URLWithString:requestStr];

NSURLRequest  *request = [NSURLRequest requestWithURL:url];

NSData *imageData = UIImageJPEGRepresentation(image, 1.0);

[sessionManager uploadTaskWithRequest:request fromData:imageData progress:nil completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error)

{

completionHandler(response,responseObject,error);

}];

}

IOS 图片上传处理 图片压缩 图片处理的更多相关文章

  1. javaweb图片上传 tomcat重新部署 图片消失

      标签: 图片上传tomcat重新部署图片消失原因分析以及解决办法 最近在做一个Javaweb的项目,涉及到图片上传,并且需要将图片通过URL回显给JSP页面,在调试的时候发现,上传到tomcat的 ...

  2. ueditor使用canvas在图片上传前进行压缩

    之前就看到H5使用canvas就可以在前端使用JS压缩图片,这次接到任务要把这个功能嵌入到ueditor里面去,以节省流量,减轻服务器压力. H5使用canvas进行压缩的代码有很多,核心原理就是创建 ...

  3. 修正ios h5上传图时的图片方向问题

     .ios上传会在exif中带一个 Orientation的属性,这个属性在windows中不会生效,在ios浏览器中会生效,造成图片在windows资源管理器中与ios浏览器中方向不一致  为了用户 ...

  4. megapix-image插件 使用Canvas压缩图片上传 解决手机端图片上传功能的问题

    最近在弄微信端的公众号.订阅号的相关功能,发现原本网页上用的uploadify图片上传功能到手机端有的手机类型上就不能用了,比如iphone,至于为啥我想应该不用多说了吧(uploadify使用fla ...

  5. 改变wordpress图片上传后的压缩质量

    WordPress 在图片上传后会默认压缩图片质量为原来的 90%,这样做的好处可以极大的加快页面的载入速度与缩小图片大小所占服务器空间. 如果希望 100% 原质量怎么办呢?如何禁止 WordPre ...

  6. 从web编辑器 UEditor 中单独提取图片上传,包含多图片单图片上传以及在线涂鸦功能

    UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具有轻量,可定制,注重用户体验等特点,开源基于MIT协议,允许自由使用和修改代码.(抄的...) UEditor是非常好用的富文 ...

  7. 大图片上传(ImageIO,注意有的图片不能上传时因为他是tiff格式)

    一下是必要的: 1.enctype="multipart/form-data" 2. //不要使用myeclipse自动生成的get.set方法(struts2中的用法) publ ...

  8. ckeditor富文本编辑器的使用和图片上传,复制粘贴图片上传

    自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...

  9. nginx代理图片上传以及访问 nginx 图片上传完整版

    nginx代理图片上传 首先需要利用nginx代理图片访问参考 https://www.cnblogs.com/TJ21/p/12609017.html 编写接受文件的controller 1 @Po ...

  10. iOS:图片上传时两种图片压缩方式的比较

    上传图片不全面的想法:把图片保存到本地,然后把图片的路径上传到服务器,最后又由服务器把路径返回,这种方式不具有扩展性,如果用户换了手机,那么新手机的沙盒中就没有服务器返回的图片路径了,此时就无法获取之 ...

随机推荐

  1. 小菜学习设计模式(三)—工厂方法(Factory Method)模式

    前言 设计模式目录: 小菜学习设计模式(一)—模板方法(Template)模式 小菜学习设计模式(二)—单例(Singleton)模式 小菜学习设计模式(三)—工厂方法(Factory Method) ...

  2. Flume NG Getting Started(Flume NG 新手入门指南)

    Flume NG Getting Started(Flume NG 新手入门指南)翻译 新手入门 Flume NG是什么? 有什么改变? 获得Flume NG 从源码构建 配置 flume-ng全局选 ...

  3. php使用post方式获得文件扩展名

    <form action="" method="post"> <input type="file" value=" ...

  4. 前端项目构建之yeoman

    各位好啊,我又和大家见面了,也许你已经不记得大明湖畔的容嬷嬷,但是只要记得博客园中的我就好,希望我的博客能像一股清风,为你驱散炎热的酷暑,好了,废话不多说,开始上干货,我今天带给大家的是前端工程化开发 ...

  5. Color Transfer between Images code实现

    上计算机视觉课老师布置的作业实现论文:Color Transfer between Images 基本思路是: 1.给定srcImg和targetImg 2.将RGB空间转为Lab空间 3.根据论文中 ...

  6. Linux入门

    参考资料:http://www.92csz.com/study/linux/ [Linux系统目录结构] 登录系统后,在当前命令窗口下输入 ls / 你会看到 以下是对这些目录的解释: /bin bi ...

  7. c++之字符型中的特殊字符回车符

    1.字符型的应用之强制类型转换: #include<iostream> using namespace std; int main() { ;i<;i++) { cout<&l ...

  8. HTML基本元素(二)

    1.图像 <img src="URL" alt="" /> 说明 src 定义图像的url alt 定义图像的替代文本 width 设置图像的宽度 ...

  9. [开源ORM] SqliteSugar 3.x .net Core版本成功上线

    SqliteSqlSugar 3.X API 作为支持.NET CORE 为数不多的ORM之一,除了具有优越的性能外,还拥有强大的功能,不只是满足你的增,删,查和改.实质上拥有更多你想像不到的功能,当 ...

  10. 20 个看起来很棒的 Web UI 工具包

    程序员们比设计师更需要这些 UI 方面的内容: 1. Mini Reminders Mini Reminders 2. Transluscent UI elements Transluscent UI ...