我试图从相机中获得尽可能好的图像,但只能找到captureStillImageAsynchronouslyFromConnection
然后直接进入的示例:
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
JPEG是有损的,有没有什么方法可以将数据作为PNG,甚至只是RGBA(BGRA,你有什么用?)。 AVCaptureStillImageOutput似乎没有任何其他NSData *方法......
实际上看看CMSampleBufferRef,似乎已经锁定为JPEG~
formatDescription = <CMVideoFormatDescription 0xfe5e1f0 [0x3e5ac650]> {
mediaType:'vide'
mediaSubType:'jpeg'
mediaSpecific: {
codecType: 'jpeg' dimensions: 2592 x 1936
}
extensions: {(null)}
}
是否还有其他方法可以获取全分辨率图片并获取原始数据?
答案 0 :(得分:10)
您需要使用不同的像素格式设置outputSettings。例如,如果您需要32位BGRA,则可以设置:
NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey, nil];
来自https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCaptureStillImageOutput_Class/Reference/Reference.html,&#34;推荐&#34;像素格式是:
kCMVideoCodecType_JPEG
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
kCVPixelFormatType_32BGRA
当然,如果您不使用JPEG输出,则无法使用jpegStillImageNSDataRepresentation:
,但这里有一个示例:
how to convert a CVImageBufferRef to UIImage
答案 1 :(得分:0)
只需更改连接的输出设置:
outputSettings 输出的压缩设置。
@property(nonatomic, copy) NSDictionary *outputSettings
您可以使用
检索支持值的NSDictionaryavailableImageDataCodecTypes 支持的图像编解码器格式,可在outputSettings中指定。 (只读)
@property(nonatomic, readonly) NSArray *availableImageDataCodecTypes