我正在使用AVCaptureVideoDataOutput
它的委托方法来操作视频帧。在委托方法中,我使用sampleBuffer
来创建 a CIImage
,然后从这里裁剪CIImage
,将其转换为 aUIImage
并显示它。不幸的是,我需要确定这个 new 的文件大小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];
});