Skip to content

CropViewLayout

Version 0.5.0

Quick start

Version 0.5.0

  <com.ave.vastgui.tools.view.cropview.CropViewLayout
      android:id="@+id/cropViewLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

Default style

Call crop

Call system cropping application

Using CropIntent to call the system cropping application.

VastCropActivity

Version 0.5.0

VastCropActivity is the default cropping application. You can easily use it in the following ways.

<activity
    android:name="com.ave.vastgui.tools.activity.app.VastCropActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
val intent = Intent(this, VastCropActivity::class.java).apply {
    data = originalImageUri
    putExtra(VastCropActivity.FRAME_TYPE, VastCropActivity.FRAME_TYPE_GRID9)
    putExtra(VastCropActivity.OUTPUT_X, 300f)
    putExtra(VastCropActivity.OUTPUT_Y, 300f)
}

Click VastCropActivity to get more information.

Frame type

Version 0.5.0

The frame type can be set by setCropFrameType .

Type Example Type Example
CIRCLE Frame circle SQUARE Frame square
GRID9 Frame grid9 RECTANGLE Frame rectangle
getBinding().cropViewLayout.setCropFrameType(CropFrameType.CIRCLE)

Frame size

Version 0.5.0

Calling setCropFrameSize to set the frame size.

getBinding().cropViewLayout.setCropFrameSize(previewWidth, previewHeight)

Size of rectangle frame type

The different length and width settings will only take effect when the preview frame type is RECTANGLE. Otherwise, the smaller value of the set length and width will be used as the actual preview frame size.

Mask color

Version 0.5.0

Calling setCropMaskColor to set the mask color.

getBinding().cropViewLayout.setCropMaskColor(color)

Alpha of mask color

It is recommended to use a color with transparency for better effect.

CropViewLayout with mask color

Stroke color

Version 0.5.0

Calling setCropFrameStrokeColor to set the stroke color of the frame.

val color = ColorUtils.colorHex2Int("#e74c3c")

getBinding().cropViewLayout.setCropFrameStrokeColor(color)

CropViewLayout with stroke color

Output image

Version 0.5.0

Compatibility with Android 9(API 28)

val bitmap:Bitmap? = 
    getBinding().cropViewLayout.getCroppedImageAboveApi28(outputX,outputY)

Compatibility under Android 9

val bitmap:Bitmap? =
    getBinding().cropViewLayout.getCroppedImageUnderApi28(outputX,outputY)

Sample code

Sample code