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];
});