Translations: 简体中文
Transformation can convert the decoded Image. Sketch has the following built-in Transformation
- CircleCropTransformation: Crop the image into a circle
- RotateTransformation: Rotate the image by a specified angle
- RoundedCornersTransformation: Crop the image into a rounded rectangle
- MaskTransformation: Cover the image with a color mask, often used to darken the image when using it as the background of a window or module.
- BlurTransformation: Blur the image
Tip
- Transformation does not support animated graphics. Please use the animatedTransformation() function for animated image.
- When using RoundedCornersTransformation, please use it with 'precision(Precision.EXACTLY)', because if the original image size is the same as When the resize size is inconsistent, the final fillet will be scaled during display, resulting in the fillet size being inconsistent with expectations.
Both ImageRequest and ImageOptions provide transformations methods for configuring Transformation
ImageRequest(context, "https://example.com/image.jpg") {
transformations(CircleCropTransformation(), RoundedCornersTransformation(20f))
}
When customizing Transformation, you need to pay attention to the implementation of the key attribute. Because the key attribute is used to build the cache key, you must ensure the uniqueness and certainty of the key attribute:
- The same Transformation inputs the same parameters and outputs the same key
- The same Transformation inputs different parameters and outputs different keys.
Tip
For custom Transformation, do not perform recycle() on the input Image of the transform method. This will cause unpredictable errors.