zoukankan      html  css  js  c++  java
  • IOS 图片上传处理 图片压缩 图片处理

    - (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);

             

        }];

        

    }

  • 相关阅读:
    软件工程实践2020_个人作业 —— 软件评测
    软件工程实践2020_结对第二次作业 —— 某次疫情统计可视化的实现
    最受欢迎的 Git 分支工作流
    结对编程作业
    软件案例分析作业
    个人项目
    个人博客作业1
    第一次作业-热身!
    面向对象第三单元
    电梯作业总结
  • 原文地址:https://www.cnblogs.com/soulDn/p/5336349.html
Copyright © 2011-2022 走看看