Skip to content

Edit Module Wiki

Sieun Ju edited this page Dec 4, 2022 · 4 revisions

A library that helps you edit images imported from your gallery.

CropImageEditView FlexibleImageEditView
crop_image_edit_view flexibleimage_example

Developer Guide

public class

CropImageEditView

Reference https://github.com/ArthurHub/Android-Image-Cropper

Attribute

Link

Important public methods

setImageBitmap(bitmap: Bitmap?)

Sets a Bitmap as the content of the CropImageView.

getEditInfo()

A function that returns things that are being edited to an object

  • Return Type
    • CropImageEditModel.
    data class CropImageEditModel(
    val bitmap: Bitmap?,
    val points: FloatArray,
    val degreesRotated: Int,
    val fixAspectRatio: Boolean,
    val aspectRatioX: Int,
    val aspectRatioY: Int,
    val flipHorizontally: Boolean,
    val flipVertically: Boolean
    )

FlexibleImageEditView

This is a view class that allows you to zoom in, zoom out, and move through gestures. When the image is out of the area, there is a logic to reposition it. It's similar to adding an Instagram story.

public methods

loadBitmap(bitmap: Bitmap?)

Load Contents Bitmap

loadBitmap(bitmap: Bitmap?, newItem: FlexibleStateItem?)

While loading the bitmap, adjust the scale and translation to the desired value.


listener(listener: FlexibleImageEditListener)

This is a listener who calls back whenever the image status value changes.

guideListener(listener: FlexibleImageGuideListener)

This is the 'Flexible ImageEdit GuideView' exclusive listener.


centerCrop()

Like ImageView ScaleType centerCrop Animation


fitCenter()

Like ImageView FitCenter Animation


getStateItem()

A function that returns the currently edited state value.

  • Return Type
    • RectF (Nullable)

getImageBitmap()

ImageView Bitmap Getter Origin Bitmap


Example

CropImageEditView

  • xml
<com.gallery.edit.CropImageEditView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:cropScaleType="centerCrop"
    app:imageBitmap="@{vm.selectPhotoBitmap}" />
  • Databinding Sample Function
@JvmStatic
@BindingAdapter("imageBitmap")
fun setCropImageEditBitmap(
    view: CropImageEditView,
    bitmap: Bitmap?
) {
    view.setImageBitmap(bitmap)
}

FlexibleImageEditView

  • xml
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

        <com.gallery.edit.FlexibleImageEditView
            android:id="@+id/ivFlexible"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:imageBitmap="@{vm.selectPhotoBitmap.first}"
            app:onStateUpdated="@{(item) -> vm.onStateItem(item)}"
            app:stateItem="@{vm.selectPhotoBitmap.second}" />

        <com.gallery.edit.FlexibleImageEditGuideView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:targetEditView="@{ivFlexible}" />
</androidx.constraintlayout.widget.ConstraintLayout>
  • Databinding Sample
internal object FlexibleImageEditBindingAdapter {

    interface FlexibleStateUpdateListener {
        fun callback(newItem: FlexibleStateItem)
    }

    @JvmStatic
    @BindingAdapter("imageBitmap", "stateItem", requireAll = false)
    fun setFlexibleEditImageBitmap(
        view: FlexibleImageEditView,
        bitmap: Bitmap?,
        stateItem: FlexibleStateItem?
    ) {
        if (stateItem == null) {
            view.loadBitmap(bitmap)
        } else {
            view.loadBitmap(bitmap, stateItem)
        }
    }

    @JvmStatic
    @BindingAdapter("onStateUpdated", requireAll = false)
    fun setFlexibleEditImageListener(
        view: FlexibleImageEditView,
        updateStateListener: FlexibleStateUpdateListener?
    ) {
        view.listener = object : FlexibleImageEditListener {
            override fun onUpdateStateItem(newItem: FlexibleStateItem) {
                try {
                    updateStateListener?.callback(newItem)
                } catch (ex: Exception) {

                }
            }
        }
    }

    @JvmStatic
    @BindingAdapter("targetEditView")
    fun setTargetEditView(
        view: FlexibleImageEditGuideView,
        targetView: FlexibleImageEditView
    ) {
        view.setImageEditView(targetView)
    }
}