TinyCrayon-iOS-SDK icon indicating copy to clipboard operation
TinyCrayon-iOS-SDK copied to clipboard

png transparent

Open AdamWorld opened this issue 5 years ago • 2 comments

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.

AdamWorld avatar Aug 15 '19 01:08 AdamWorld

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

antoniomdk avatar Aug 23 '19 16:08 antoniomdk

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)

adrianorezena avatar Sep 23 '19 20:09 adrianorezena