gpt4 book ai didi

cocoa - 如何使用 AVCaptureFlashMode

转载 作者:行者123 更新时间:2023-12-03 16:13:21 25 4
gpt4 key购买 nike

我正在制作一个应用程序,可以将图像拼接成全景场景。我希望能够以编程方式打开 iPhone 4 上的闪光灯 LED。

我该怎么做?

我阅读了文档,发现我需要使用 AVCaptureFlashMode

但我不知道2如何使用它?

如有任何帮助,我们将不胜感激。

<小时/>

更新了下面的代码。感谢 SIF!

NSError* error = nil;    NSLog(@"Setting up LED");    if([captDevice hasTorch] == NO)    {        NSLog(@"Error: This device doesnt have a torch");    }    if([captDevice isTorchModeSupported:AVCaptureTorchModeOn] == NO)    {        NSLog(@"Error: This device doesnt support AVCaptureTorchModeOn");    }    AVCaptureSession* captureSession = [[AVCaptureSession alloc] init];    AVCaptureDeviceInput* videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:captDevice error:&error];    AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];    if (videoInput && videoOutput)     {        [captureSession addInput:videoInput];        [captureSession addOutput:videoOutput];        if([captDevice lockForConfiguration:&error])        {            if (flag == YES) {                captDevice.torchMode = AVCaptureTorchModeOn;            } else {                captDevice.torchMode = AVCaptureTorchModeOff;            }                       [captDevice unlockForConfiguration];        }        else         {            NSLog(@"Could not lock device for config error: %@", error);        }        [captureSession startRunning];    }    else     {        NSLog(@"Error: %@", error);    }

如何关闭它?

最佳答案

AVCaptureDevice* d = nil;

// find a device by position
NSArray* allDevices = [AVCaptureDevice devices];
for (AVCaptureDevice* currentDevice in allDevices) {
if (currentDevice.position == AVCaptureDevicePositionBack) {
d = currentDevice;
}
}

// at this point, d may still be nil, assuming we found something we like....

NSError* err = nil;
BOOL lockAcquired = [d lockForConfiguration:&err];

if (!lockAcquired) {
// log err and handle...
} else {
// flip on the flash mode
if ([d hasFlash] && [d isFlashModeSupported:AVCaptureFlashModeOn] ) {
[d setFlashMode:AVCaptureFlashModeOn];
}

[d unlockForConfiguration];
}

关于cocoa - 如何使用 AVCaptureFlashMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3204008/

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