在這裏需要幫助,已經解決了幾個小時,但無濟於事。如何在橫向模式而不是縱向模式下捕獲avfoundation
我想在AVCaptureVideoPreviewLayer中捕捉圖像並顯示它的預覽,它以橫向模式顯示。但是,當我抓住圖像時,它被顯示爲肖像模式。
我不知道爲什麼,我希望有人可以幫助我:)
感謝您的閱讀。
當實時取景
捕獲並中的UIImageView所示
- (void)addStillImageOutput
{
[self setStillImageOutput:[[AVCaptureStillImageOutput alloc] init]];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey,nil];
[[self stillImageOutput] setOutputSettings:outputSettings];
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;
}
}
[[self captureSession] addOutput:[self stillImageOutput]];
}
- (void)captureStillImage
{
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 isVideoOrientationSupported])
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationLandscapeLeft) {
//NSLog(@"2222UIInterfaceOrientationLandscapeLeft");
[videoConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
}
if (orientation == UIInterfaceOrientationLandscapeRight)
{//NSLog(@"222UIInterfaceOrientationLandscapeRight");
[videoConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
}
}
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];
//NSData *jpgImageData = UIImageJPEGRepresentation(image, 0.9);
//UIImage *jpgImage = [[UIImage alloc]initWithData:jpgImageData];
[self setStillImage:image];
self.imageExifDict = (__bridge NSDictionary *)exifAttachments;
////NSLog(@"NSdictionary from CFDict %@",self.imageExifDict);
//
[[NSNotificationCenter defaultCenter] postNotificationName:kImageCapturedSuccessfully object:nil];
}];
}
我通過從NSData的圖像以UIImage的
self.capturedImage.image = [[self captureManager] stillImage];
你可以發表一些代碼,請你如何'AVCaptureVideoPreviewLayer,它顯示在橫向模式。我有同樣的問題。 – user2545330 2013-08-21 07:04:44
@ user2545330編輯我的帖子。我希望它有幫助! – Desmond 2013-08-22 01:52:53