添加:AVFoundation库
#import <AVFoundation/AVFoundation.h>
.h
@interface xxxxx : UIViewController {
AVCaptureSession *AVSession;
}
@property(nonatomic,retain) AVCaptureSession *AVSession;
.m
@synthesize AVSession;
.......
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaTy pe:AVMediaTypeVideo];
if (device.torchMode == AVCaptureTorchModeOff)
{
// Create an AV session
AVCaptureSession *session = [[AVCaptureSession alloc] init];
// Create device input and add to current session
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error: nil];
[session addInput:input];
// Create video output and add to current session
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[session addOutput:output];
// Start session configuration
[session beginConfiguration];
[device lockForConfiguration:nil];
// Set torch to on
[device setTorchMode:AVCaptureTorchModeOn];
[device unlockForConfiguration];
[session commitConfiguration];
// Start the session
[session startRunning];
// Keep the session around
[self setAVSession:AVSession];
[output release];
}
else
{
[AVSession stopRunning]; //AVSession是定义在头文件的 (属性)
[AVSession release], AVSession = nil;
}
#import <AVFoundation/AVFoundation.h>
.h
@interface xxxxx : UIViewController {
}
@property(nonatomic,retain) AVCaptureSession *AVSession;
.m
@synthesize AVSession;
本文介绍如何使用AVFoundation库在iOS应用中控制摄像头的手电筒功能。通过创建AVCaptureSession并配置摄像头设备来实现手电筒的开关操作。
912

被折叠的 条评论
为什么被折叠?



