-->

How can I extract an AVMetadataObject from a UIIma

2020-02-19 13:50发布

问题:

I'd like to use iOS 7's new barcode scanning functionality with a UIImage instead of live capture from one of the device's camera. I already have the detection working fine with an AVCaptureDeviceInput.

The best way I think to do this would be to create a concrete subclass of AVCaptureInput that provides media data to an AVCaptureSession from a UIImage. However, I can't find any documentation or examples on how to subclass AVCaptureInput, so I'm at a loss.

An alternative would be to override the media stream from an existing AVCaptureDeviceInput, but since those API's are private and I'd like to publish my app on the App Store, this isn't ideal.

Ultimately, I'll likely end up doing this using a 3rd party barcode library like ZXing or ZBar, but it seems like a waste to not be able to use Apple's built-in functionality here.

回答1:

life is easy. You can use CIDetector instead. Convert an image into CIImage to be decoded by CIDetector.