Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

png transparent #38

Open
AdamWorld opened this issue Aug 15, 2019 · 2 comments
Open

png transparent #38

AdamWorld opened this issue Aug 15, 2019 · 2 comments

Comments

@AdamWorld
Copy link

Hi!
I selected png and expected result like following.

주석 2019-08-15 091356

But the result is that transparent area is filled with black.
Would you please help me how i can solve this problem?

Regards,
Adam.

@antoniomdk
Copy link

I have the same problem. Did someone figure it out?

@adrianorezena
Copy link

My solution was:

extension UIImage {

func alphaPixelsData() -> [UInt8]? {
    let size = self.size
    let dataSize = size.width * size.height
    var pixelData = [UInt8](repeating: 0, count: Int(dataSize))
    let colorSpace = CGColorSpaceCreateDeviceGray()
    let context = CGContext(data: &pixelData,
                            width: Int(size.width),
                            height: Int(size.height),
                            bitsPerComponent: 8,
                            bytesPerRow: Int(size.width),
                            space: colorSpace,
                            bitmapInfo: CGImageAlphaInfo.alphaOnly.rawValue)
    guard let cgImage = self.cgImage else { return nil }
    context?.draw(cgImage, in: CGRect(x: 0, y: 0, width: size.width, height: size.height))

    return pixelData
}

}

let maskView = TCMaskView(image: image)
maskView.delegate = self

if let alphaMaskArray = image.alphaPixelsData() {
    maskView.setInitialMaskWithArray(alphaMaskArray)
}

maskView.presentFrom(rootViewController: viewController, animated: true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants