gpt4 book ai didi

ios - 如何在 iPhone 上获取快门速度、光圈和 ISO 值

转载 作者:可可西里 更新时间:2023-11-01 04:48:55 26 4
gpt4 key购买 nike

我写过这样的代码:

-(IBAction)startCapture
{
//session object
captureSession = [[AVCaptureSession alloc]init];
captureSession.sessionPreset = AVCaptureSessionPresetMedium;

AVCaptureVideoPreviewLayer *previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
previewLayer.frame = CGRectMake(0, 10, 320, 200); ////self.view.frame; //
[self.view.layer addSublayer:previewLayer];

NSError *error = nil;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

//input object
AVCaptureDeviceInput *inputDevice = [[AVCaptureDeviceInput alloc]initWithDevice:device error:&error];
[captureSession addInput:inputDevice];

stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[stillImageOutput setOutputSettings:outputSettings];

[captureSession addOutput:stillImageOutput];
[captureSession startRunning];
}

-(IBAction) 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; }
}

NSLog(@"about to request a capture from: %@", stillImageOutput);
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);

NSLog(@"exif Attachments:%@",exifAttachments);
if (exifAttachments)
{
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];

UIImage *image = [[UIImage alloc] initWithData:imageData];
self.vImage.image = image;
// Do something with the attachments.

}
else
NSLog(@"no attachments");
}];
}

捕捉图像。但我想知道拍摄时的快门速度、ISO 值和光圈。我怎样才能找出这些值?我尝试了以下方法:

[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
NSDictionary *exifDict = (NSDictionary *)exifAttachments;
NSLog(@"\n exif data = %@",exifDict);

CFNumberRef aperaturevalue = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifApertureValue, NULL);
NSNumber *num = (NSNumber *)aperaturevalue;
NSLog(@"\n AperatureValue : %@",num);

CFNumberRef shutter = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifShutterSpeedValue, NULL);
NSNumber *shunum = (NSNumber *)shutter;
NSLog(@"\n shuttervalue : %@",shunum);

CFArrayRef isoRef = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifISOSpeedRatings, NULL);
NSArray *iso = (NSArray *)isoRef;
NSLog(@"Iso value : %@",iso);
}

但它给出的输出是这样的:

exif data = {
ApertureValue = "2.970853605202583";
ExposureMode = 0;
ExposureProgram = 2;
FNumber = "2.8";
Flash = 32;
MeteringMode = 1;
SceneType = 1;
SensingMethod = 2;
WhiteBalance = 0;
}
2011-06-23 14:35:14.955 CameraExample[1464:307]
AperatureValue : (null)
2011-06-23 14:35:14.981 CameraExample[1464:307]
shuttervalue : (null)
2011-06-23 14:35:14.999 CameraExample[1464:307] Iso value : (null)

最佳答案

尝试在您的 block 中添加此代码:

CFDictionaryRef exifDictRef = CMGetAttachment(imageSampleBuffer,kCGImagePropertyExifDictionary, NULL);
NSDictionary *exifDict = (NSDictionary *)exifDictRef;
for (id key in exifDict) {
NSLog(@"key = %@, value = %@",key,[exifDict objectForKey:key]);
}

您应该在这些键中找到您要查找的值:

  • kCGImagePropertyExifShutterSpeedValue(结果是一个 NSNumber)
  • kCGImagePropertyExifApertureValue(结果是一个 NSNumber)
  • kCGImagePropertyExifISOSpeedRatings(结果是一个 NSArray)

关于ios - 如何在 iPhone 上获取快门速度、光圈和 ISO 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6435548/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com