BradLarson / GPUImage2

GPUImage 2 is a BSD-licensed Swift framework for GPU-accelerated video and image processing.
BSD 3-Clause "New" or "Revised" License
4.88k stars 611 forks source link

PictureOutput with transparency #298

Closed deshan closed 5 years ago

deshan commented 5 years ago

Hi, My code is like below, what I need is transparency for the area which has 0 alpha. But what I get is alpha replace with black color.

let imageInput = PictureInput(image: inputImage)
let filter = CustomAlphaFilter()
let pictureOutput = PictureOutput()

pictureOutput.imageAvailableCallback = {image in
            // Save image to photos
        }

imageInput --> filter --> pictureOutput
imageInput.processImage(synchronously: true)

Thanks

IMG-8288

deshan commented 5 years ago

Few changes and fixed

//PictureOutput
func cgImageFromFramebuffer{
...
   CGImage(... bitmapInfo:CGBitmapInfo(rawValue: CGImageAlphaInfo.last.rawValue) ...)
...
}

// png representation must use when saving image
// https://stackoverflow.com/questions/1489250/uiimagewritetosavedphotosalbum-save-as-png-with-transparency
pictureOutput?.imageAvailableCallback = {image in
            let data : Data? = UIImagePNGRepresentation(image)
            if let data = data, let pngImage = UIImage(data: data) {
                UIImageWriteToSavedPhotosAlbum(pngImage, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)
            }
        }