拍照时可以获取相机的曝光值(而无需将其保存到SavedPhotos)。一种 光度计 iPhone上的应用程序可以通过使用一些私有API来执行此操作。

该应用程序仅在iPhone 3GS上执行此操作,因此我想它可能与EXIF数据相关,该数据在创建图像时与此信息填充。

这一切都适用于3GS。

iPhone OS 4.0有什么变化吗?现在有常规的方法来获取这些价值吗?

是否有人有用于使用这些相机/照片设置值的工作代码示例?

谢谢

有帮助吗?

解决方案

使用iOS 4.0中的AvFoundation,您可以弄乱曝光,专门参考Avcapturedevice,这是一个链接 Avcapturedevice Ref. 。不确定它是否正是您想要的,但是您可以环顾四周,并可能找到一些有用的东西

其他提示

如果需要实时*曝光信息,则可以使用AvcaptureVideOdataOutput捕获视频。每个帧CMSampleBuffer都充满了描述相机当前状态的有趣数据。

*最多30 fps

我想我终于找到了真正的EXIF数据的领导。我要发布实际的代码还需要一段时间,但是我认为应该在此期间公开。

谷歌 capturetillimageasynchronallyconnection. 。这是 AvCaptureStillimageOutput 以下是文档的摘录(长期以来寻求):

ImagedatAsampleBuffer-捕获的数据。缓冲区附件可能包含适合图像数据格式的元数据。例如,包含JPEG数据的缓冲区可能会携带KcgimagePropertyexifdictionary作为附件。有关密钥和值类型的列表,请参见ImageIO/CGIMAGEPROPERTIES.H。

与合作的示例 AvCaptureStillimageOutput 请参阅WWDC 2010示例代码, avcam.

和平,O。

这是完整的解决方案。不要忘记导入适当的框架和标题。在Capturenow方法中的Exifattachments var中,您会找到所需的所有数据。

#import <AVFoundation/AVFoundation.h>
#import <ImageIO/CGImageProperties.h>

AVCaptureStillImageOutput *stillImageOutput;
AVCaptureSession *session;    

- (void)viewDidLoad
    {
        [super viewDidLoad];
        [self setupCaptureSession];
        // Do any additional setup after loading the view, typically from a nib.    
    }

    -(void)captureNow{


        AVCaptureConnection *videoConnection = nil;
        for (AVCaptureConnection *connection in stillImageOutput.connections)
        {
            for (AVCaptureInputPort *port in [connection inputPorts])
            {
                if ([[port mediaType] isEqual:AVMediaTypeVideo] )
                {
                    videoConnection = connection;
                    break;
                }
            }
            if (videoConnection) { break; }
        }

        [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection
         completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *__strong error) {
            CFDictionaryRef exifAttachments = CMGetAttachment( imageDataSampleBuffer, kCGImagePropertyExifDictionary, NULL);
            if (exifAttachments)
            {
                // Do something with the attachments.
                NSLog(@"attachements: %@", exifAttachments);
            }
            else
              NSLog(@"no attachments");

            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
            UIImage *image = [[UIImage alloc] initWithData:imageData];
            }];

    }


    // Create and configure a capture session and start it running
    - (void)setupCaptureSession
    {
        NSError *error = nil;

        // Create the session
        session = [[AVCaptureSession alloc] init];

        // Configure the session to produce lower resolution video frames, if your
        // processing algorithm can cope. We'll specify medium quality for the
        // chosen device.
        session.sessionPreset = AVCaptureSessionPreset352x288;

        // Find a suitable AVCaptureDevice
        AVCaptureDevice *device = [AVCaptureDevice
                                   defaultDeviceWithMediaType:AVMediaTypeVideo];
        [device lockForConfiguration:nil];

        device.whiteBalanceMode = AVCaptureWhiteBalanceModeLocked;
        device.focusMode = AVCaptureFocusModeLocked;
        [device unlockForConfiguration];

        // Create a device input with the device and add it to the session.
        AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
                                                                            error:&error];
        if (!input) {
            // Handling the error appropriately.
        }
        [session addInput:input];




        stillImageOutput = [AVCaptureStillImageOutput new];
        NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
        [stillImageOutput setOutputSettings:outputSettings];
        if ([session canAddOutput:stillImageOutput])
            [session addOutput:stillImageOutput];


        // Start the session running to start the flow of data
        [session startRunning];
        [self captureNow];

    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top