*このコードで画像をキャプチャしていますが、ボタンをクリックしたときにもビデオを録画して保存する必要があるため、どうすればよいか教えてください。画像を正常にキャプチャしてフォトアルバムに保存したため、実際には取得できませんが、ビデオも録画して保存する必要があるため、誰かより良いアイデアを教えてください*
- (void)viewDidLoad
{
front=NO;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
barPicker.value = hue;
pickerArr=[[NSArray alloc]initWithObjects:@"01",@"02",@"03",@"04",@"05",@"06",@"07",@"08",@"09",@"10", nil];
flashlightOn=YES;
[flashButton setImage:[UIImage imageNamed:@"off.png"] forState:UIControlStateNormal];
[camraButton setImage:[UIImage imageNamed:@"camra.png"] forState:UIControlStateNormal];
session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;
CALayer *viewLayer = self.vImagePreview.layer;
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];
[self.vImagePreview addSubview:flashButton];
[self.vImagePreview addSubview:camraButton];
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
if (!input) {
// Handle the error appropriately.
NSLog(@"ERROR: trying to open camera: %@", error);
}
else
{
[session addInput:input];
[stillImageOutput setOutputSettings:outputSettings];
[session addOutput:stillImageOutput];
}
[session startRunning];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(IBAction) captureNow
{
if (!front)
{
if (flashlightOn) {
AVCaptureDevice *device1 = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device1 hasTorch] && [device1 hasFlash])
{
[device1 lockForConfiguration:nil];
[device1 setTorchMode:AVCaptureTorchModeOn];
[device1 setFlashMode:AVCaptureFlashModeOn];
[device1 unlockForConfiguration];
}
}
}
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);
if (exifAttachments) {
}
else {
}
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
image.image = [[UIImage alloc] initWithData:imageData];
}];
}