0

I am developing barcode reader application, in which I want to zoom camera view by tapping on camera. I used following approach to zoom camera view but its not work for the iOS6 and iPhone4(iOS7) device. Please any one help me on this:

if ([self.device respondsToSelector:@selector(setActiveFormat:)] &&
        [self.device.activeFormat respondsToSelector:@selector(videoMaxZoomFactor)] &&
        [self.device respondsToSelector:@selector(setVideoZoomFactor:)]){
        float maxZoom = 0;
        if ([self.device.activeFormat respondsToSelector:@selector(videoZoomFactorUpscaleThreshold)]){
            maxZoom = self.device.activeFormat.videoZoomFactorUpscaleThreshold;
        } else {
            maxZoom = self.device.activeFormat.videoMaxZoomFactor;
        }
        float maxZoomTotal = self.device.activeFormat.videoMaxZoomFactor;
//        maxZoom =2.0;
//        maxZoomTotal = maxZoomTotal +2;
        if ([self.device respondsToSelector:@selector(setVideoZoomFactor:)] && maxZoomTotal > 1.1){
            videoZoomSupported = true;
            if (param_ZoomLevel1 != 0 && param_ZoomLevel2 != 0){
                if (param_ZoomLevel1 > maxZoomTotal * 100){
                    param_ZoomLevel1 = (int)(maxZoomTotal * 100);
                }
                if (param_ZoomLevel2 > maxZoomTotal * 100){
                    param_ZoomLevel2 = (int)(maxZoomTotal * 100);
                }
                firstZoom = 0.01 * param_ZoomLevel1;
                secondZoom = 0.01 * param_ZoomLevel2;
            } else {
                if (maxZoomTotal > 2){
                    if (maxZoom > 1.0 && maxZoom <= 2.0){
                        firstZoom = maxZoom;
                        secondZoom = maxZoom * 2;
                    } else
                        if (maxZoom > 2.0){
                            firstZoom = 2.0;
                            secondZoom = 4.0;
                        }
                }
            }
        } else {
        }
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
  • 1
    activeFormat is available in iOS 7.0 and later. In iOS 6 your else (empty) statement will be fire. About IPhone 4, you need to ask your device if it can make zoom. It might not be able. – Onik IV Dec 09 '14 at 15:21
  • Can you give me any idea How can I ask to device it can make zoom or not ? – Divya Bhaloidiya Dec 09 '14 at 15:25
  • 1
    NSLog(@"Formats supported:%@",[self.device.formats description]); Adding this before your if statement, and running in iPhone 4, must tell you the supported format. More info here: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/#//apple_ref/occ/instp/AVCaptureDevice/formats – Onik IV Dec 09 '14 at 15:32

0 Answers0