Skip to main content
VESDK/Android/Features

Transform

The transform tool of the VideoEditor SDK for Android unifies cropping, flipping and rotation operations. Learn how to add custom crop ratios to the library

Transform tool

Our transform tool unifies cropping, flipping and rotation operations in one feature. The VideoEditor SDK holds various preset crop ratios (e.g. 16:9) that can easily be complemented by any crop ratio you deem necessary.

The backend settings are implemented in the TransformSettings class and displayed using the TransformToolPanel. If you want to customize the appearance of this tool, take a look at the customization section.

As an example, you could create the following configuration:

// Add aspect assets to backend
settingsList.config.getAssetMap(CropAspectAsset::class.java).clear().add(
CropAspectAsset.FREE_CROP,
CropAspectAsset("my_crop_1_1", 1, 1, false),
CropAspectAsset("my_crop_16_9", 16, 9, false),
CropAspectAsset("my_crop_9_16", 9, 16, false),
CropAspectAsset("my_crop_4_3", 4, 3, false),
CropAspectAsset("my_crop_3_4", 3, 4, false),
CropAspectAsset("my_crop_3_2", 3, 2, false),
CropAspectAsset("my_crop_2_3", 2, 3, false)
)
// Add Items to UI
settingsList.configure<UiConfigAspect> {
it.setAspectList(
CropAspectItem("my_crop_free", R.string.pesdk_transform_button_freeCrop),
CropAspectItem("my_crop_1_1"),
CropAspectItem("my_crop_16_9"),
CropAspectItem("my_crop_9_16"),
CropAspectItem("my_crop_4_3"),
CropAspectItem("my_crop_3_4"),
CropAspectItem("my_crop_3_2"),
CropAspectItem("my_crop_2_3")
)
}

Forcing specific ratios#

Per default the SDK chooses the best matching aspect for the input photo. This is in general the FREE_CROP. In order to force your users to crop their image to one of the available crop ratios, you need to remove the FREE_CROP option from the assets, to ensure that a user can’t remove the forced crop ratio afterward.

// Remove default Assets and add your own aspects
settingsList.configure<AssetConfig> {
it.getAssetMap(CropAspectAsset::class.java)
.clear().add(
CropAspectAsset("aspect_1_1", 1, 1, false),
CropAspectAsset("aspect_16_9", 16, 9, false),
CropAspectAsset("aspect_9_16", 9, 16, false)
)
}
// Add your own Asset to UI config and select the Force crop Mode.
settingsList.configure<UiConfigAspect> {
it.setAspectList(
CropAspectItem("aspect_1_1"),
CropAspectItem("aspect_16_9"),
CropAspectItem("aspect_9_16")
)
it.forceCropMode = UiConfigAspect.ForceCrop.SHOW_TOOL_NEVER
}

You can also force a specific aspect for portrait and landscape images. (In this case you do not need to removing the FREE_CROP option)

// Set force crop by asset id, make sure you have added that asset.
settingsList.configure<TransformSettings> {
it.setForceCrop("aspect_16_9", "aspect_9_16")
}