问题
I have followed the basic setup instructions on GPUImage2's github for filtering live video and capturing an image from video just so I can setup a basic camera. When the user taps a button, I try to capture the image from the filter using this code specifically:
let pictureOutput = PictureOutput()
pictureOutput.encodedImageFormat = .JPEG
pictureOutput.imageAvailableCallback = {image in
// Do something with the image
self.previewImageView.image = image
}
self.filter! --> pictureOutput
For whatever reason, the imageAvailableCallback is never called and I am unable to get the image from the camera.
回答1:
The -->
calls addTarget
and addTarget
appends to targets (TargetContainer
) which appends a weak reference. So you should make sure the target will be available on callback. For example just place the pictureOutput variable at the top of your class.
来源:https://stackoverflow.com/questions/37687753/imageavailablecallback-never-called-in-basic-gpuimage2-camera-setup