私は自分のiPadでビデオから画像をキャプチャしようとしています。私はAppleのAVCamの例を出発点として使用しました。AVFoundationを使用してビデオから画像をキャプチャする
私のアプリケーションでビデオを見て、そこから写真を撮ることができました。私の問題は、結果画像のピクセルサイズが間違っていることです。私はフルスクリーンの画像(1024x768)が欲しいですが、私は小さなもの(1024x720)を取得します。
ここ@property (retain) AVCaptureStillImageOutput *stillImageOutput;
@property (retain) AVCaptureVideoPreviewLayer *previewLayer;
@property (retain) AVCaptureSession *captureSession;
@property (retain) AVCaptureConnection *captureConnection;
@property (retain) UIImage *stillImage;
写真を撮るためのコード:
それらは私のインスタンス変数です
- (void)takePicture
{
AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in [[self 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: %@", [self stillImageOutput]);
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:videoConnection
completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) {
CFDictionaryRef exifAttachments = CMGetAttachment(imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
if (exifAttachments) {
NSLog(@"attachements: %@", exifAttachments);
} else {
NSLog(@"no attachments");
}
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self setStillImage:image];
[image release];
[[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil];
}];
}
私は、最終的な画像のサイズを変更すると考えますが、このソリューションは、画像の品質を低下させます。 また、辞書に値PixelYDimension = 720;
が含まれていることに気がつきましたが、私はそれと対話する方法を見つけることができないようです。
ご協力いただければ幸いです。 あらかじめありがとうございます。
アレックス。
編集:私は私が言うと、「動画から写真を撮る」ことを指摘したいと思いは、私はビデオをiPadのカメラからのライブ来ているとそれが記録ではないことを意味しました。