Phonegap Build iOS camera.getPicture() quality parameter not working

后端 未结 2 1201
醉话见心
醉话见心 2021-01-25 20:21

I have written a Phonegap application and compiled it using the Build service. My application calls the camera in this block of code:

function capturePhoto() {



        
相关标签:
2条回答
  • 2021-01-25 20:43

    This is the code the plugin uses for processing the image after taking the picture:

    - (NSData*)processImage:(UIImage*)image info:(NSDictionary*)info options:(CDVPictureOptions*)options
    {
        NSData* data = nil;
    
        switch (options.encodingType) {
            case EncodingTypePNG:
                data = UIImagePNGRepresentation(image);
                break;
            case EncodingTypeJPEG:
            {
                if ((options.allowsEditing == NO) && (options.targetSize.width <= 0) && (options.targetSize.height <= 0) && (options.correctOrientation == NO)){
                    // use image unedited as requested , don't resize
                    data = UIImageJPEGRepresentation(image, 1.0);
                } else {
                    if (options.usesGeolocation) {
                        NSDictionary* controllerMetadata = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
                        if (controllerMetadata) {
                            self.data = data;
                            self.metadata = [[NSMutableDictionary alloc] init];
    
                            NSMutableDictionary* EXIFDictionary = [[controllerMetadata objectForKey:(NSString*)kCGImagePropertyExifDictionary]mutableCopy];
                            if (EXIFDictionary) {
                                [self.metadata setObject:EXIFDictionary forKey:(NSString*)kCGImagePropertyExifDictionary];
                            }
    
                            if (IsAtLeastiOSVersion(@"8.0")) {
                                [[self locationManager] performSelector:NSSelectorFromString(@"requestWhenInUseAuthorization") withObject:nil afterDelay:0];
                            }
                            [[self locationManager] startUpdatingLocation];
                        }
                    } else {
                        data = UIImageJPEGRepresentation(image, [options.quality floatValue] / 100.0f);
                    }
                }
            }
                break;
            default:
                break;
        };
    
        return data;
    }
    

    So, if options.encodingType is PNG the image quality isn't change. The default value is JPG, so the problem isn't there.

    But then check the

    if ((options.allowsEditing == NO) && (options.targetSize.width <= 0) && (options.targetSize.height <= 0) && (options.correctOrientation == NO))
    

    allowsEditing is NO by default

    targetSize.width and targetSize.height are 0 by default

    correctOrientation is NO by default

    So all the conditions of the if are meet, and no change in quality is done.

    It sounds like a bug as it isn't mentioned anywhere that you have to specify any other value to make the quality param work.

    So, what can you do now?

    You can file an issue on the cordova jira page https://issues.apache.org/jira/browse/CB And/or you can pass any param to change the default value and make the code to skip the if and go to the else with the quality code. Changing any of this should work:

      allowEdit : true,
      targetWidth: 100,
      targetHeight: 100,
      correctOrientation: true
    

    EDIT: there is already a bug open https://issues.apache.org/jira/browse/CB-6190

    EDIT 2: I fixed the issue, you can get the changes with cordova plugin add https://github.com/apache/cordova-plugin-camera or wait until it's released to NPM

    0 讨论(0)
  • 2021-01-25 20:47

    There is no issue. iOS has larger pictures. They call it a feature.

    http://lifeinlofi.com/more/iphone-photo-sizes-2007-2013/

    Jesse

    0 讨论(0)
提交回复
热议问题