hafiz
fun ImageBitmap.toUIImage(): UIImage? { val width = this.width val height = this.height val buffer = IntArray(width * height) this.readPixels(buffer) val colorSpace = CGColorSpaceCreateDeviceRGB() val context = CGBitmapContextCreate( data = buffer.refTo(0), width = width.toULong(), height = height.toULong(), bitsPerComponent = 8u, bytesPerRow = (4 * width).toULong(), space = colorSpace, bitmapInfo = CGImageAlphaInfo.kCGImageAlphaPremultipliedLast.value ) val cgImage = CGBitmapContextCreateImage(context) return cgImage?.let { UIImage.imageWithCGImage(it) } }
A modern programming language that makes developers happier.