2

拍照时可以获取相机的曝光值(无需将其保存到 SavedPhotos)。iPhone 上的测光表应用程序可能通过使用一些私有 API 来做到这一点。

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

这都适用于3GS。

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

有没有人有一个工作代码示例来获取这些相机/照片设置值?

谢谢

4

4 回答 4

8

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

*高达 30 帧/秒

于 2011-05-22T07:44:36.633 回答
2

使用 iOS 4.0 中的 AVFoundation 你可以搞乱曝光,具体参考 AVCaptureDevice,这里是一个链接AVCaptureDevice ref。不确定它是否正是你想要的,但你可以看看 AVFoundation 并可能找到一些有用的东西

于 2010-07-03T17:02:17.687 回答
2

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

谷歌captureStillImageAsynchronouslyFromConnection它是AVCaptureStillImageOutput的一个功能,以下是文档的摘录(长期寻找):

imageDataSampleBuffer - 捕获的数据。缓冲区附件可能包含适合图像数据格式的元数据。例如,包含 JPEG 数据的缓冲区可以携带 kCGImagePropertyExifDictionary 作为附件。有关键和值类型的列表,请参阅 ImageIO/CGImageProperties.h。

有关使用AVCaptureStillImageOutput的示例,请参阅AVCam下的 WWDC 2010 示例代码。

和平,O.

于 2010-08-02T06:45:25.567 回答
0

这是完整的解决方案。不要忘记导入适当的框架和标题。在 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];

    }
于 2013-04-10T04:59:50.193 回答