CropViewLayout¶
Quick start¶
<com.ave.vastgui.tools.view.cropview.CropViewLayout
android:id="@+id/cropViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Call crop¶
Call system cropping application¶
Using CropIntent to call the system cropping application.
VastCropActivity¶
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¶
The frame type can be set by setCropFrameType
.
Type | Example | Type | Example |
---|---|---|---|
CIRCLE | SQUARE | ||
GRID9 | RECTANGLE |
getBinding().cropViewLayout.setCropFrameType(CropFrameType.CIRCLE)
Frame size¶
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¶
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.
Stroke color¶
Calling setCropFrameStrokeColor
to set the stroke color of the frame.
val color = ColorUtils.colorHex2Int("#e74c3c")
getBinding().cropViewLayout.setCropFrameStrokeColor(color)
Output image¶
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)