captureStillImageAsynchronouslyFromConnection没有JPG中介 [英] captureStillImageAsynchronouslyFromConnection without JPG intermediary
问题描述
我正试图从相机中获得尽可能好的图像,但只能找到 captureStillImageAsynchronouslyFromConnection
的示例,然后直接进入:
I'm trying to get as good an image as possible from the camera, but can only find examples that captureStillImageAsynchronouslyFromConnection
and then go straight to:
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
JPEG有损并且全部,有没有办法将数据作为PNG,甚至只是RGBA (BGRA,你有什么?)。 AVCaptureStillImageOutput似乎没有任何其他NSData *方法....
JPEG being lossy and all, is there any way to get the data as PNG, or even just RGBA (BGRA, what-have-you?). AVCaptureStillImageOutput doesn't seem to have any other NSData* methods....
实际上看看CMSampleBufferRef,好像已经锁定为JPEG~
Actually looking at the CMSampleBufferRef, it seems like it's already locked as JPEG ~
formatDescription = <CMVideoFormatDescription 0xfe5e1f0 [0x3e5ac650]> {
mediaType:'vide'
mediaSubType:'jpeg'
mediaSpecific: {
codecType: 'jpeg' dimensions: 2592 x 1936
}
extensions: {(null)}
}
还有其他方法可以采取全额措施res picture并获取原始数据?
Is there some other way to take a full-res picture and get the raw data?
推荐答案
您需要使用不同的像素格式设置outputSettings。例如,如果你想要32位BGRA,你可以设置:
You'll need to set the outputSettings with a different pixel format. If you want 32-bit BGRA, for example, you can set:
NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey, nil];
From https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCaptureStillImageOutput_Class/Reference/Reference.html, the "recommended" pixel formats are:
-
kCMVideoCodecType_JPEG
-
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
-
kCVPixelFormatType_32BGRA
kCMVideoCodecType_JPEG
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
kCVPixelFormatType_32BGRA
当然,如果您不使用JPEG输出,则不能使用 jpegStillImageNSDataRepresentation:
,但这里有一个例子:
如何转换a CVImageBufferRef到UIImage
Of course, if you're not using JPEG output, you can't use jpegStillImageNSDataRepresentation:
, but there's an example here:
how to convert a CVImageBufferRef to UIImage
这篇关于captureStillImageAsynchronouslyFromConnection没有JPG中介的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!