0
我使用AVCaptureVideoDataOutput
及其委托方法来操纵视频帧。在委托方法中,我使用sampleBuffer
来创建CIImage
,从这里我裁剪CIImage
,将其转换为UIImage
并显示它。不幸的是,我需要确定这个新的文件大小UIImage
,但它返回0
。代码工作,图像剪裁精美,一切。我只是不明白为什么它没有数据!从CIImage的UIImage - 数据长度为零?
为什么会这样呢?相关的代码如下:
//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];
});
只是一个NB这两条线 - 'data.length'返回一个unsigned int,那么你的'NSLog'说法应该是这样的,而不是:'的NSLog (@“图像大小为%u”,data.length)' – lxt 2013-02-25 23:42:45
这是事实 - 尽管它对输出没有影响。我试图筛选Apple的文档,仅仅是因为我知道CoreImage实际上不是图像,只是数据表示。但在这一点上它超出了我为什么转换时不会有数据。 – bgoers 2013-02-25 23:47:55
是的,我害怕我难倒你的实际问题 - 假设当你在调用'UIImageJPEGRepresentation'后断点时你的'NSData'对象实际上有数据。 – lxt 2013-02-25 23:49:39