CaptureStillImageAsynchronouslyFromConnection存在一個奇怪的問題。如果在鏡像視頻時使用jpegStillImageNSDataRepresentation保存圖像,則相機膠捲中的圖像將順時針旋轉90度。但是,如果它沒有鏡像,方向就很好。 我會發布代碼,任何人都有這個問題/知道修復?AVCaptureMovieFileOutput將照片保存到相機膠捲時導致錯誤的方向
更新:只是跑了一些測試,高度和寬度(640x480)都很好,反映了設備的方向。當我以縱向拍攝照片時,它會報告UIImageOrientationLeft和鏡像時的UIImageOrientationLeftMirrored。
更新2:當我在相機膠捲中查看保存的照片時,圖像的預覽具有正確的方向,當您在照片之間滑動時的圖像也是如此,但是當照片完全加載時,它會旋轉90度。這可能是相機膠捲問題嗎? (我在4.3.3)
- (void) captureImageAndSaveToCameraRoll
{
AVCaptureConnection *stillImageConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
if ([stillImageConnection isVideoOrientationSupported])
[stillImageConnection setVideoOrientation:[self orientation]];
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:stillImageConnection
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {
if (error) {
if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) {
[[self delegate] captureManager:self didFailWithError:error];
}
}
};
if (imageDataSampleBuffer != NULL) {
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[library writeImageToSavedPhotosAlbum:[image CGImage]
orientation:(ALAssetOrientation)[image imageOrientation]
completionBlock:completionBlock];
[image release];
[library release];
}
else
completionBlock(nil, error);
if ([[self delegate] respondsToSelector:@selector(captureManagerStillImageCaptured:)]) {
[[self delegate] captureManagerStillImageCaptured:self];
}
}];
}
調試這可能會有所幫助,如果你在這兩種模式下輸出image.size和imageOrientation,你會得到什麼值? – mackross 2011-06-15 01:58:50
只是跑了一些測試,高度和寬度(640x480)都很好,反映了設備的方向。當我以縱向拍攝照片時,它會報告UIImageOrientationLeft和鏡像時的UIImageOrientationLeftMirrored。 – 2011-06-15 02:13:21