0

我正在我的 iOS 应用程序中实现相机应用程序功能,问题是当我在阳光下单击图片时,它会使我的应用程序崩溃,但它在 deamLight 中运行良好。

我点击图片的代码

        loadingOutlet.hidden=NO;
        imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.delegate=self;
        [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
        [self presentViewController: imagePicker animated:YES completion:nil ];
        [self.view bringSubviewToFront:imageView];

        CameraPic=YES;

这是用于在上传时压缩图像UIImageView

-(void)loadImgInNSData
 {
     double size;
     int  compressionRatio=1;
     while ([imgDataCompressImg length]>50000) 
     {
         size = [imgDataCompressImg length];
         compressionRatio=compressionRatio*0.5;
         imgDataCompressImg=UIImageJPEGRepresentation([[UIImage alloc]  initWithData:imgDataCompressImg],compressionRatio);
         NSLog(@"%i",[imgDataCompressImg length]);
        if (size-[imgDataCompressImg length]<500000)
        {
            break;
        }
    }

} 

请尽快帮助我

4

1 回答 1

0

将您的图像压缩长度增加超过 5000 万,例如:

        [imgDataCompressImg length]>80000

           -(void)loadImgInNSData
             {

              double size;
              int  compressionRatio=1;
              while ([imgDataCompressImg length]>80000) {
              size = [imgDataCompressImg length];
              compressionRatio=compressionRatio*0.5;
              imgDataCompressImg=UIImageJPEGRepresentation([[UIImage alloc]    initWithData:imgDataCompressImg],compressionRatio);
              NSLog(@"%i",[imgDataCompressImg length]);
              if (size-[imgDataCompressImg length]<800000) {
              break;
              }
            }
于 2013-10-24T07:21:29.520 回答