TinyCrayon-iOS-SDK
TinyCrayon-iOS-SDK copied to clipboard
png transparent
Hi! I selected png and expected result like following.
But the result is that transparent area is filled with black. Would you please help me how i can solve this problem?
Regards, Adam.
I have the same problem. Did someone figure it out?
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)