captureStillImageAsynchronouslyFromConnection没有JPG中介 [英] captureStillImageAsynchronouslyFromConnection without JPG intermediary

查看:981
本文介绍了captureStillImageAsynchronouslyFromConnection没有JPG中介的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆