0

AVCaptureVideoDataOutputビデオ フレームを操作するデリゲート メソッドと共に を使用しています。デリゲート メソッドでは、 を使用してsampleBufferを作成しCIImage、ここから を切り取り、CIImageに変換してUIImage表示します。残念ながら、この新しい のファイルサイズを特定する必要がありますUIImageが、0. コードは機能し、画像は美しくトリミングされています。なぜデータがないのかわかりません!

これはなぜでしょうか?関連するコードは次のとおりです。

//In delegate method, given sampleBuffer...
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault,
                                  sampleBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer 
                                                  options:(NSDictionary *)attachments];

...


dispatch_async(dispatch_get_main_queue(), ^(void) {
    CGRect rect = [self drawFaceBoxesForFeatures:features forVideoBox:clap
                                                 orientation:curDeviceOrientation];

    CIImage *cropped = [ciImage imageByCroppingToRect:rect];
    UIImage *image = [[UIImage alloc] initWithCIImage:cropped];

    NSData *data = UIImageJPEGRepresentation(image, 1);
    NSLog(@"Image size is %d", data.length); //returns 0???

    [imageView setImage:image];

    [image release];
});
4

1 に答える 1