6

を使用してカメラから画像をキャプチャしていますcaptureStillImageAsynchronouslyFromConnection

画像は上下逆さまに保存されています。を使用して画像を保存しようとしました

UIImage *flippedImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUp]

しかし、この向きはメタデータにのみあり、ファイルからデータをコピーして処理すると、処理された画像が上下逆になります。(簡単に見ると、元の画像は縦に表示されていますが、処理/フィルター処理された画像は逆になっています)。

ビデオキャプチャの向きを設定する正しい方法は何ですか?

AVCaptureStillImageOutputビデオ プレビュー レイヤーで向きを設定しましたが、オブジェクトのバッファーにキャプチャされたデータには影響しません。

ヘッダーを読みましたAVCaptureStillImageOutputが、カメラのプレビューの向きを画像バッファーに強制する方法の説明がないようです。

例えば- (AVMetadataObject *)transformedMetadataObjectForMetadataObject:(AVMetadataObject *)metadataObject connection:(AVCaptureConnection *)connection NS_AVAILABLE_IOS(6_0);

ありがとう

4

2 に答える 2

4

-videoOrientation「問題」は画像の向きです。iOS カメラは、撮影した画像を変換するプロパティを設定した場合を除き、1 つの向きでのみ画像を返します。したがって、さまざまな問題が発生する可能性があります。

  1. videoOrientation正しく設定されていない
  2. videoOrientationALL に設定されていません

videoOrientation プロパティは、単一のバッファーではなく、静止画像とビデオのキャプチャに対してのみ機能します。
このスニペットは、Apple AVCamサンプル コードからのたんけんです。

    [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];

    [AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];

    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

        if (imageDataSampleBuffer)
        {
            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
            UIImage *image = [[UIImage alloc] initWithData:imageData];
            [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:nil];
        }
    }]; <br>

最初にプレビュー ビューに従って向きを設定し、後でショットを撮影し、後で正しい向きでアセット ライブラリに保存します。

于 2014-03-16T12:38:54.943 に答える
1

あなたが言ったように、そうすることでメタデータを変更するだけです。実際に画像を反転するには、このメソッドを使用する必要があります。

これを試して:

- (UIImage *)flipImage:(UIImage *)image
{
    UIGraphicsBeginImageContext(image.size);
    CGContextDrawImage(UIGraphicsGetCurrentContext(),CGRectMake(0, 0, image.size.width, image.size.height),image.CGImage);
    UIImage *i = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return i;
}

詳細はこちら

于 2015-04-16T16:13:07.293 に答える