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

compose multiplatform #27

Open
mahramane opened this issue Jun 11, 2023 · 1 comment
Open

compose multiplatform #27

mahramane opened this issue Jun 11, 2023 · 1 comment

Comments

@mahramane
Copy link

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

@yandroidUA
Copy link

yandroidUA commented Sep 1, 2023

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)

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

2 participants