captureStillImageAsynchronouslyFromConnection没有JPG中介

Kao*_*ire 6 image-capture uiimage ios

我试图从相机中获得尽可能好的图像,但只能找到示例,captureStillImageAsynchronouslyFromConnection然后直接进入:

NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];    
UIImage *image = [[UIImage alloc] initWithData:imageData];
Run Code Online (Sandbox Code Playgroud)

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)}
}
Run Code Online (Sandbox Code Playgroud)

是否有其他方法可以拍摄全分辨率照片并获取原始数据?

squ*_*les 10

您需要使用不同的像素格式设置outputSettings.例如,如果您想要32位BGRA,您可以设置:

NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey, nil];
Run Code Online (Sandbox Code Playgroud)

来自https://developer.apple.com/library/mac/#documentation/AVFoundation/Reference/AVCaptureStillImageOutput_Class/Reference/Reference.html,"推荐"的像素格式为:

  • kCMVideoCodecType_JPEG
  • kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
  • kCVPixelFormatType_32BGRA

当然,如果您不使用JPEG输出,则无法使用jpegStillImageNSDataRepresentation:,但这里有一个示例: 如何将CVImageBufferRef转换为UIImage