Compose-Cropper icon indicating copy to clipboard operation
Compose-Cropper copied to clipboard

compose multiplatform

Open mahramane opened this issue 2 years ago • 1 comments

Hi Thank you for your good library Is it possible to develop for compose multiplatform? https://www.jetbrains.com/lp/compose-multiplatform/

mahramane avatar Jun 11 '23 11:06 mahramane

Just in case, you can easily move core part of the library to the KMM. I used that code snippet to crop an image on the iOS side:

@OptIn(ExperimentalForeignApi::class)
actual class ImageCropUtilsImpl : ImageCropUtils {

    override fun cropTo(source: ImageBitmap, rect: IntRect): ImageBitmap {
        val skiaImage = Image.makeFromBitmap(source.asSkiaBitmap())
        val encoded = skiaImage.encodeToData()
        if (encoded == null) {
            Napier.e { "Failed to encode an image" }
            return source
        }
        val oldImage = UIImage(encoded.bytes.toData())
        val platformRect = CGRectMake(
            x = rect.left.toDouble(),
            y = rect.top.toDouble(),
            width = rect.width.toDouble(),
            height = rect.height.toDouble()
        )
        val imageRef = CGImageCreateWithImageInRect(oldImage.CGImage, platformRect)
        val result = UIImage.imageWithCGImage(imageRef, oldImage.scale, oldImage.imageOrientation)
        CGImageRelease(imageRef)
        return UIImagePNGRepresentation(result)?.toByteArray()?.toImageBitmap() ?: source
    }
}

However, I used that awesome library as a reference and guide for implementation, eventually I ended up having a bit different code and a bit different set of features that suites my needs (not so rich as provided by that awesome library)

yandroidUA avatar Sep 01 '23 18:09 yandroidUA