πŸš€πŸžπŸ’ͺ Collection of Images, Modifiers, utility functions for Jetpack Compose to expand and enrich displaying, manipulating, scaling, resizing, zooming, and getting cropped ImageBitmap based on selection area

Overview

Compose Image on Steroids

Collection of Images, Modifiers, utility functions for Jetpack Compose to expand and enrich displaying, manipulating, scaling, resizing, zooming, and getting cropped ImageBitmap based on selection area, before/after image to with handle to show partial of both images and more is cooking up

intro_image.mp4

Gradle Setup

To get a Git project into your build:

  • Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
allprojects {
  repositories {
      ...
      maven { url 'https://jitpack.io' }
  }
}
  • Step 2. Add the dependency
dependencies {
    implementation 'com.github.SmartToolFactory:Compose-Image:'
}

ImageWithConstraints

A composable that lays out and draws a given ImageBitmap. This will attempt to
size the composable according to the ImageBitmap's given width and height.

ImageScope returns constraints, width and height of the drawing area based on contentScale and rectangle of imageBitmap drawn. When a bitmap is displayed scaled to fit area of Composable space used for drawing image is represented with ImageScope.imageWidth and ImageScope.imageHeight. When we display a bitmap 1000x1000px with ContentScale.Crop if it's cropped to 500x500px ImageScope.rect returns IntRect(250,250,750,750).

This composable enables building other Image based Composables that require you to know spaces around ImageBitmap based on ContentScale or which section of Bitmap is drawn to Canvas

@Composable
fun ImageWithConstraints(
    modifier: Modifier = Modifier,
    imageBitmap: ImageBitmap,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Fit,
    contentDescription: String? = null,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
    filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
    drawImage: Boolean = true,
    content: @Composable ImageScope.() -> Unit = {}
) {
    imageScope: ImageScope->

}

returns ImageScope which is

@Stable
interface ImageScope {
    /**
     * The constraints given by the parent layout in pixels.
     *
     * Use [minWidth], [maxWidth], [minHeight] or [maxHeight] if you need value in [Dp].
     */
    val constraints: Constraints

    /**
     * The minimum width in [Dp].
     *
     * @see constraints for the values in pixels.
     */
    val minWidth: Dp

    /**
     * The maximum width in [Dp].
     *
     * @see constraints for the values in pixels.
     */
    val maxWidth: Dp

    /**
     * The minimum height in [Dp].
     *
     * @see constraints for the values in pixels.
     */
    val minHeight: Dp

    /**
     * The maximum height in [Dp].
     *
     * @see constraints for the values in pixels.
     */
    val maxHeight: Dp

    /**
     * Width of area inside BoxWithConstraints that is scaled based on [ContentScale]
     * This is width of the [Canvas] draws [ImageBitmap]
     */
    val imageWidth: Dp

    /**
     * Height of area inside BoxWithConstraints that is scaled based on [ContentScale]
     * This is height of the [Canvas] draws [ImageBitmap]
     */
    val imageHeight: Dp

    /**
     * [IntRect] that covers boundaries of [ImageBitmap]
     */
    val rect: IntRect
}
  • drawImage param is to set whether this Composable should draw on Canvas. ImageWithConstraints can be used not only for drawing but providing required info for its content or child Composables so child can draw ImageBitmap as required by developer.

ImageWithThumbnail

ImageWithThumbnail displays thumbnail of bitmap it draws in corner specified by ThumbnailState.position. When touch position is close to thumbnail position if ThumbnailState.dynamicPosition is set to true moves thumbnail to corner specified by ThumbnailState.moveTo

@Composable
fun ImageWithThumbnail(
    modifier: Modifier = Modifier,
    imageBitmap: ImageBitmap,
    contentScale: ContentScale = ContentScale.Fit,
    alignment: Alignment = Alignment.Center,
    contentDescription: String?,
    thumbnailState: ThumbnailState = rememberThumbnailState(),
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
    filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
    drawOriginalImage: Boolean = true,
    onDown: ((Offset) -> Unit)? = null,
    onMove: ((Offset) -> Unit)? = null,
    onUp: (() -> Unit)? = null,
    onThumbnailCenterChange: ((Offset) -> Unit)? = null,
    content: @Composable ImageScope.() -> Unit = {}
) {

}

TransformLayout

Composable that changes scale of its content with handles, translates its position when dragged inside bounds.

@Composable
fun TransformLayout(
    modifier: Modifier = Modifier,
    enabled: Boolean = true,
    handleRadius: Dp = 15.dp,
    handlePlacement: HandlePlacement = HandlePlacement.Corner,
    onDown: (Transform) -> Unit = {},
    onMove: (Transform) -> Unit = {},
    onUp: (Transform) -> Unit = {},
    content: @Composable () -> Unit
) {

}

MorphLayout

Composable that changes dimensions of its content with handles, translates its position when dragged inside bounds.

⚠️ Be careful about maximum dimension can be assigned to this Composable with handles because maximum width and height depends on how a Composable, Column for instance, lays out its children. It can be expanded up to remaining space if other siblings occupy rest of the parent's available space set with parent Layout

@Composable
fun MorphLayout(
    modifier: Modifier = Modifier,
    containerModifier: Modifier = Modifier,
    enabled: Boolean = true,
    handleRadius: Dp = 15.dp,
    handlePlacement: HandlePlacement = HandlePlacement.Corner,
    updatePhysicalSize: Boolean = false,
    onDown: () -> Unit = {},
    onMove: (DpSize) -> Unit = {},
    onUp: () -> Unit = {},
    content: @Composable () -> Unit
) {
}

ZoomableImage

Zoomable image that zooms in and out in [ [minZoom], [maxZoom] ] interval and translates zoomed image based on pointer position. Double tap gestures reset image translation and zoom to default values with animation. Callbacks notify user that gesture has started, going on finished with [ZoomData] that contains current transformation information

@Composable
fun ZoomableImage(
    modifier: Modifier = Modifier,
    imageBitmap: ImageBitmap,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Fit,
    contentDescription: String? = null,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
    filterQuality: FilterQuality = DrawScope.DefaultFilterQuality,
    initialZoom: Float = 1f,
    minZoom: Float = 1f,
    maxZoom: Float = 5f,
    limitPan: Boolean = true,
    zoomEnabled: Boolean = true,
    panEnabled: Boolean = true,
    rotationEnabled: Boolean = false,
    clipTransformToContentScale: Boolean = false,
    consume: Boolean = true,
    onGestureStart: (ZoomData) -> Unit = {},
    onGesture: (ZoomData) -> Unit = {},
    onGestureEnd: (ZoomData) -> Unit = {}
) {
}

Modifier.zoom

Modifier that zooms, pans, and rotates any Composable it set to. when [clip] is true Modifier.clipToBounds() is used to limit content inside Composable bounds consume param is for Modifier.pointerInput to consume current events to prevent other gestures like scroll, drag or transform to initiate. Callbacks notify user that gesture has started, going on finished with [ZoomData] that contains current transformation information

fun Modifier.zoom(
    key: Any?,
    consume: Boolean = true,
    clip: Boolean = true,
    zoomState: ZoomState,
    onGestureStart: (ZoomData) -> Unit = {},
    onGesture: (ZoomData) -> Unit = {},
    onGestureEnd: (ZoomData) -> Unit = {},
) 
You might also like...
A CLI utility to convert Jetpack Compose compiler metrics and reports to beautified 😍 HTML page
A CLI utility to convert Jetpack Compose compiler metrics and reports to beautified 😍 HTML page

Compose Compiler Reports to HTML Generator A CLI utility to convert Jetpack Compose compiler metrics and reports to beautified 😍 HTML page. Made with

Utility for monitoring Genshin Impact in-game status, built with Jetpack Compose, Accompanist, and more
Utility for monitoring Genshin Impact in-game status, built with Jetpack Compose, Accompanist, and more

yumetsuki An utility app for monitoring in-game status on Genshin Impact like resin status, realm currency, expedition, daily commission status, etc.

Flippable - A Jetpack Compose utility library to create flipping Composable views with 2 sides
Flippable - A Jetpack Compose utility library to create flipping Composable views with 2 sides

πŸ’³ Flippable A Jetpack Compose utility library to create flipping Composable views with 2 sides. Built with ❀︎ by Wajahat Karim and contributors Demo

A Collection on all Jetpack compose UI elements, Layouts, Widgets and Demo screens to see it's potential
A Collection on all Jetpack compose UI elements, Layouts, Widgets and Demo screens to see it's potential

ComposeCookBook Declarative UI A Collection of all Jetpack compose UI elements, Layouts, Widgets and Demo screens to see it's potential. Jetpack Compo

🎺 Orchestra is a collection of Android custom view compatible libraries for Jetpack Compose.
🎺 Orchestra is a collection of Android custom view compatible libraries for Jetpack Compose.

Orchestra 🎺 Jetpack Compose compatible libraries using Balloon, ColorPickerView, PowerSpinner. Balloon Add below codes to your root build.gradle file

A Collection of major Jetpack compose UI components which are commonly used.πŸŽ‰πŸ”πŸ‘Œ
A Collection of major Jetpack compose UI components which are commonly used.πŸŽ‰πŸ”πŸ‘Œ

SSComposeCookBook A Collection of major Jetpack compose UI components which are commonly used. Introduction Jetpack Compose is a modern toolkit for bu

ComposeAnimations - Collection of nice animations created with Jetpack Compose

CertificateStack.kt CardStackDemo.mp4 SwipeButton.kt SwipeButton.mp4

πŸ‚ Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.
πŸ‚ Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, and Fresco.

Landscapist πŸ‚ Jetpack Compose image loading library which can fetch and display network images using Glide, Coil, Fresco Usecase You can see the use

🎨 Jetpack Compose canvas library that helps you draw paths, images on canvas with color pickers and palettes
🎨 Jetpack Compose canvas library that helps you draw paths, images on canvas with color pickers and palettes

🎨 Jetpack Compose canvas library that helps you draw paths and images on canvas with color pickers and palettes. Sketchbook also provides useful components and functions that can easily interact with canvas.

Comments
  • [Feature request] Zoom in and out should happen when the user is pinching, and not always at the center of the image

    [Feature request] Zoom in and out should happen when the user is pinching, and not always at the center of the image

    I know that this is not trivial, but it would be really good to have the zoom action to happen where actually the user is pinching the image, instead of happening always at the center of the image.

    Use case is that, if I have a picture and what to zoom on a specific location (e.g. the face of a person's full body pic), I currently have to zoom and then pan, often multiple times, because the zoom always is happening at the center of the image.

    The Android Gallery app and Google Photos already implement this feature and would be nice to have the same in this library as well.

    opened by leinardi 0
  • Stretched image on after side

    Stretched image on after side

    Hi, I am using the BeforeAfter image in my project. I came across a bug. It is reproducible. The after image stretched on my test phone. My phone is: Samsung Galaxy A5 Android: 8.0.0

    streetch

    opened by Cutta 2
Releases(1.2.2)
Owner
Smart Tool Factory
πŸš€ Building colorful and shiny things with Compose(Jetpack Compose Artist🎨)
Smart Tool Factory
Holi is a lightweight Jetpack Compose library of colors, gradients and cool utility functions for all your palette needs!

Holi A library of colors, gradients and utils built using Jetpack Compose for Android Features A wide collection of colors from different palettes for

Siddhesh Patil 167 Dec 5, 2022
Holi is a lightweight Jetpack Compose library of colors, gradients and cool utility functions for all your palette needs!

Holi is a lightweight Jetpack Compose library of colors, gradients and cool utility functions for all your palette needs!

Sid Patil 167 Dec 5, 2022
A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Why Not Compose! A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Md. Mahmudul Hasan Shohag 186 Jan 1, 2023
Jetpack-compose-uis - A collection of some UIs using Jetpack Compose. built using Katalog

Jetpack Compose UIs This is a collection of some UIs using Jetpack Compose. It i

Mori Atsushi 3 Dec 15, 2022
Dynamic Badge with customizable features as max number before displaying with +, color, shadow, border, corner radius, font properties and more written with Jetpack Compose

✏️?? Dynamic Badge with customizable features as max number before displaying with +, color, shadow, border, corner radius, font properties and more written with Jetpack Compose. Displays numbers either in circle or rounded rectangle shape based on badge count and selected threshold to transform from circle to rounded rectangle.

Smart Tool Factory 4 Jul 27, 2022
An Android Jetpack Compose library for displaying on-screen messages

InfoBar Compose An Android Jetpack Compose library for displaying on-screen messages. Unlike the built-in Snackbar from the Compose Material library,

Radu Salagean 78 Dec 20, 2022
A Jetpack Compose component used for displaying Markdown-formatted text.

MarkdownText A library for displaying Markdown contents within Jetpack Compose. Uses Coil Current limitations Lists that are annotated with the * must

Arnau Mora 4 Dec 15, 2022
This repo is to demonstrate the jetpack compose 's canvas api's usage and creating an icon pack using the basic functions.

Jetpack Compose Canvas API Demo App We all know that Jetpack Compose has now reached the 1.0.0 release milestone. This is a huge change we can say for

vikas kumar 32 Dec 15, 2022
Mocking with Jetpack Compose - stubbing and verification of Composable functions

Mockposable A companion to mocking libraries that enables stubbing and verification of functions annotated with @androidx.compose.runtime.Composable.

Jesper Γ…man 21 Nov 15, 2022
Capturable - πŸš€Jetpack Compose utility library for capturing Composable content and transforming it into Bitmap ImageπŸ–ΌοΈ

Capturable ?? A Jetpack Compose utility library for converting Composable content into Bitmap image ??️ . Made with ❀️ for Android Developers and Comp

Shreyas Patil 494 Dec 29, 2022