ios - 没有 JPG 中介的 captureStillImageAsynchronouslyFromConnection

标签 ios uiimage image-capture

我试图从相机中获得尽可能好的图像,但只能找到 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/

相关文章:

ios - 在 Swift 上使用 GPUImage 过滤器捕获图像

android - java.lang.OutOfMemoryError - BitmapFactory.decode(strPath)

ios - 旋转 UIView;如何防止旋转过程中的剪裁?

iOS-UIButton系统选择图像

iOS Realm readOnly 导致空结果

iphone - 无法根据 xib 中的按钮更新 UIView 中的 UIImage 变量

iphone - 如何在 iPhone 中使用 avFoundation 拍摄方形照片,就像在 Instagram 应用程序中一样?

ios - 如何在 iOS 和 WatchKit 中更改图像 tintColor

ios - 在 iOS 计算器上创建退格键

android - Cordova:如何在不使用相机应用程序的情况下拍照