compose-avatar-cropper
1.0.0indexedLightweight avatar cropping UI with touch gestures, pinch-to-zoom, pan, double-tap reset, circle and square masks, smooth animations, and simple state-driven crop API.
Lightweight avatar cropping UI with touch gestures, pinch-to-zoom, pan, double-tap reset, circle and square masks, smooth animations, and simple state-driven crop API.
Compose Avatar Cropper is a lightweight and powerful image cropping library built with Kotlin Multiplatform and Jetpack Compose. It is designed for selecting and cropping user avatars with support for touch gestures.
This library is available on Maven Central.
Add the dependency to your build.gradle.kts (commonMain):
commonMain.dependencies {
implementation("cn.mucute:compose-avatar-cropper:1.0.0")
}
Use the AvatarCropper composable to display the cropping interface.
import cn.mucute.compose.avatar.cropper.AvatarCropper
import cn.mucute.compose.avatar.cropper.CropShape
import cn.mucute.compose.avatar.cropper.rememberCropState
@Composable
{
cropState = rememberCropState()
AvatarCropper(
imageBitmap = imageBitmap,
state = cropState,
shape = CropShape.Circle,
modifier = Modifier.fillMaxSize(),
backgroundColor = Color.Black
)
Button(onClick = {
result = cropState.crop(imageBitmap)
}) {
Text()
}
}
AvatarCropper
CropState
crop(imageBitmap: ImageBitmap): ImageBitmap?: Performs the crop operation and returns the result. Returns null if the crop area is invalid.reset(imageBitmap: ImageBitmap): Resets the image scale and position to fit the screen.updateShape(newShape: CropShape, imageBitmap: ImageBitmap): Dynamically changes the crop shape.Compose Avatar Cropper 是一个基于 Kotlin Multiplatform 和 Jetpack Compose 构建的轻量级且强大的图片裁剪库。专为用户头像选择和裁剪设计,支持流畅的手势操作。
该库已发布到 Maven Central。
在您的 build.gradle.kts (commonMain) 中添加依赖:
commonMain.dependencies {
implementation("cn.mucute:compose-avatar-cropper:1.0.0")
}
使用 AvatarCropper 组件来显示裁剪界面。
import cn.mucute.compose.avatar.cropper.AvatarCropper
import cn.mucute.compose.avatar.cropper.CropShape
import cn.mucute.compose.avatar.cropper.rememberCropState
@Composable
fun MyCropperScreen {
cropState = rememberCropState()
AvatarCropper(
imageBitmap = imageBitmap,
state = cropState,
shape = CropShape.Circle,
modifier = Modifier.fillMaxSize(),
backgroundColor = Color.Black
)
Button(onClick = {
result = cropState.crop(imageBitmap)
}) {
Text()
}
}
AvatarCropper
CropState
crop(imageBitmap: ImageBitmap): ImageBitmap?: 执行裁剪操作并返回结果。如果裁剪区域无效则返回 null。reset(imageBitmap: ImageBitmap): 重置图片缩放和位置以适应屏幕。updateShape(newShape: CropShape, imageBitmap: ImageBitmap): 动态更改裁剪形状。Copyright 2024 mucute
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.
| Parameter | Type | Default | Description |
|---|
imageBitmap | ImageBitmap | Required | The source image to be cropped. |
state | CropState | rememberCropState() | State object to control cropping logic. |
shape | CropShape | CropShape.Square | The shape of the cropping mask (Circle or Square). |
backgroundColor | Color | Color.Transparent | Background color behind the image. |
modifier | Modifier | Modifier | Modifier for the layout. |
| 参数 | 类型 | 默认值 | 描述 |
|---|
imageBitmap | ImageBitmap | 必填 | 需要裁剪的源图片。 |
state | CropState | rememberCropState() | 控制裁剪逻辑的状态对象。 |
shape | CropShape | CropShape.Square | 裁剪遮罩的形状 (Circle 或 Square)。 |
backgroundColor | Color | Color.Transparent | 图片背后的背景颜色。 |
modifier | Modifier | Modifier | 布局修饰符。 |
Surfaced from shared tags and platforms — no rankings paid for.