【问题标题】:captureStillImageAsynchronouslyFromConnection without JPG intermediary没有 JPG 中介的 captureStillImageAsynchronouslyFromConnection
【发布时间】:2012-07-20 00:27:11
【问题描述】:

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

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

【问题讨论】:

  • 那么你最终是如何获得 PNG 的数据的呢?你是不是只用了 kCVPixelFormatType_32BGRA 而不是 kCMVideoCodecType_JPEG?
  • 谢谢,但第 167 行显示您还在使用 jpegStillImageNSDataRepresentation 吗?你如何转换成PNG?
  • 我对凌乱的代码不好——那是一个错误的 ifdef。第 104 行是关键。 (和 170-183)。
  • 没问题,但是你在哪里转换成PNG输出呢?不清楚...

标签: ios uiimage image-capture


【解决方案1】:

您需要使用不同的像素格式设置 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

【讨论】:

  • 哇。我应该尝试一下,尽管availableImageDataCodecTypes 说只有 jpeg 可用。我想其他人不是编解码器,所以这是有道理的。快乐多了。谢谢! :)
  • 因此,如果您想要 PNG 而不是 JPEG 输出,请使用 kCVPixelFormatType_32BGRA,然后使用其中一个答案从 CVImageBufferRef 转换为 UIImage?谢谢!
【解决方案2】:

只需更改连接的输出设置:

输出设置 输出的压缩设置。

@property(nonatomic, copy) NSDictionary *outputSettings

您可以使用

检索受支持值的 NSDictionary

availableImageDataCodecTypes 可以在 outputSettings 中指定的支持的图像编解码器格式。 (只读)

@property(nonatomic, readonly) NSArray *availableImageDataCodecTypes

【讨论】:

  • 一个新创建的 AVCaptureStillImageOutput 提供了一个数组,其中包含一项用于 availableImageDataCodecTypes: (jpeg)。这是否意味着我完全是“全分辨率”的 SOL?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-07
  • 2022-01-12
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多