ios – captureStillImageAsynchronouslyFromConnection没有JPG中介

我试图从相机中获得尽可能好的图像,但只能找到captureStill ImageAsynchronouslyFromConnection的示例,然后直接进入:
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

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...