我试图从相机中获得尽可能好的图像,但只能找到 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)}
}
有没有其他方法可以拍摄全分辨率照片并获取原始数据?
最佳答案
您需要使用不同的像素格式设置 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 ,“推荐的”像素格式是:
kCMVideoCodecType_JPEG
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
kCVPixelFormatType_32BGRA
当然,如果您不使用 JPEG 输出,则不能使用 jpegStillImageNSDataRepresentation:
,但这里有一个示例:
how to convert a CVImageBufferRef to UIImage
关于ios - 没有 JPG 中介的 captureStillImageAsynchronouslyFromConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11571242/