Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 1.83 KB

long_image_grid_thumbnails.md

File metadata and controls

39 lines (28 loc) · 1.83 KB

Improve the clarity of long images in grid lists

Translations: 简体中文

For example, in GirdLayoutManager, the width and height of ImageView is 400x400, and the width and height of the image are 30000x960. Sketch automatically calculates that Resize is 400x400 and Precision defaults to LESS_PIXELS. In this case, the inSampleSize calculated according to Resize is 16, and the decoded thumbnail size is 1875x60, this thumbnail is extremely blurry and no content can be discerned

For this situation, you can use LongImageClipPrecisionDecider to dynamically calculate Precision. LongImageClipPrecisionDecider will return when encountering a long image. SAME_ASPECT_RATIO or EXACTLY (specified when creating), otherwise LESS_PIXELS is returned. This not only ensures that long images have a clear thumbnail, but also ensures fast loading of non-long images.

Notice:

  1. The default implementation of long image rules is DefaultLongImageDecider, you can also create LongImageClipPrecisionDecider Use custom rules when
  2. SAME_ASPECT_RATIO and EXACTLY will use BitmapRegionDecoder to crop the original image, so you can get a clearer thumbnail.

Use

imageView.displayImage("https://www.sample.com/image.jpg") {
    resizePrecision(LongImageClipPrecisionDecider(Precision.SAME_ASPECT_RATIO))
}