在 iPhone OS 4.0 上从相机获取曝光值

发布于 2024-09-08 06:16:16 字数 341 浏览 5 评论 0原文

拍照时可以获取相机的曝光值(无需将其保存到 SavedPhotos)。 iPhone 上的照度计 应用程序可能会使用一些私有 API 来实现此目的。

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

这都适用于3GS。

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

有人有获取这些相机/照片设置值的工作代码示例吗?

谢谢

Exposure values from camera can be acquired when you take picture (without saving it to SavedPhotos). A light meter application on iPhone does this, probably by using some private API.

That application does it on iPhone 3GS only, so I guess it may be somehow related to EXIF data which is populated with this information when the image is created.

This all applies to 3GS.

Has anything changed with iPhone OS 4.0?
Is there a regular way to get these values now?

Does anyone have a working code example for taking these camera/photo setting values?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

自我难过 2024-09-15 06:16:16

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

*高达 30 fps

If you want realtime* exposure information, you can capture a video using AVCaptureVideoDataOutput. Each frame CMSampleBuffer is full of interesting data describing the current state of the camera.

*up to 30 fps

洒一地阳光 2024-09-15 06:16:16

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

With AVFoundation in iOS 4.0 you can mess with exposure, refer specifically to AVCaptureDevice, here is a link AVCaptureDevice ref. Not sure if its exactly what you want but you can look around AVFoundation and probably find some useful stuff

无风消散 2024-09-15 06:16:16

我想我终于找到了真正的 EXIF 数据。我还需要一段时间才能发布实际的代码,但我认为这应该同时公开。

Google 从连接异步捕获StillImage。它是 AVCaptureStillImageOutput 的一个函数,以下是文档的摘录(长期以来一直在寻找):

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

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

和平,
奥。

I think I finally found the lead to the real EXIF data. It'll be a while before I have actual code to post, but I figured this should be publicized in the meantime.

Google captureStillImageAsynchronouslyFromConnection. It's a function of AVCaptureStillImageOutput and following is an excerpt from the documentation (long sought for):

imageDataSampleBuffer -
The data that was captured.
The buffer attachments may contain metadata appropriate to the image data format. For example, a buffer containing JPEG data may carry a kCGImagePropertyExifDictionary as an attachment. See ImageIO/CGImageProperties.h for a list of keys and value types.

For an example of working with AVCaptureStillImageOutput see WWDC 2010 sample code, under AVCam.

Peace,
O.

姐不稀罕 2024-09-15 06:16:16

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

    }

Here is the complete solution. Dont forget to import appropriate frameworks and headers.
In the exifAttachments var in capturenow method you'll find all data you are looking for.

#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];

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文