Compose-Cropper
Compose-Cropper copied to clipboard
compose multiplatform
Hi Thank you for your good library Is it possible to develop for compose multiplatform? https://www.jetbrains.com/lp/compose-multiplatform/
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)