Skip to content

Latest commit

 

History

History
55 lines (35 loc) · 2.54 KB

transformation_zh.md

File metadata and controls

55 lines (35 loc) · 2.54 KB

Transformation

翻译:English

通过 Transformation 可以对解码得到的 Bitmap 进行转换,Sketch 内置了以下几种 Transformation

注意:

  1. Transformation 不支持动图,动图请使用 animatedTransformation() 函数
  2. 在使用 RoundedCornersTransformation 时请搭配 'resizePrecision(Precision.EXACTLY)' 使用,因为如果原图尺寸和 resize 尺寸不一致时,最终圆角在显示时会被缩放,导致圆角大小和期待的不一致

配置

ImageRequestImageOptions 都提供了 transformations 方法用于配置 Transformation

imageView.displayImage("https://www.sample.com/image.jpg") {
    transformations(CircleCropTransformation(), RoundedCornersTransformation(20f))
}

自定义

自定义 Transformation 时需要注意 key 属性的实现

因为 key 属性用于在构建 Transformation 列表时去除重复的 Transformation,所以要保证 key 属性的唯一性和确定性:

注意:自定义的 Transformation 不要对 transform 方法的 input Bitmap 执行 recycle() 或将其放到 BitmapPool 中,这会造成不可预知的错误