bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.46k stars 6.11k forks source link

Prevent upscaling #4649

Open azurh opened 2 years ago

azurh commented 2 years ago

Glide Version: 4.12.0

Integration libraries: No, it's a sandbox project to isolate the issue.

Device/Android Version: Google Pixel 3XL, Android 11

Issue details / Repro steps / Use case background: What I want sounds rather simple. I don't want images to get upscaled. I'm fine with downscaling which is an obvious thing to expect with such a library but if the image is too small, I don't want it upscaled to fit the bounds of the ImageView since it looks pixelated.

Glide load line / GlideModule (if any) / list Adapter code (if any):

Glide.with(this)
  .load(URL)
  .downsample(DownsampleStrategy.CENTER_INSIDE)
  .into(imageView)

Layout XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <ImageView
        android:id="@+id/imageview"
        android:layout_width="300dp"
        android:layout_height="300dp" />

</LinearLayout>

Stack trace / LogCat: N/A

sjudd commented 2 years ago

CenterInside as the transform and downsample strategy will avoid upscaling. See http://bumptech.github.io/glide/javadocs/4130/index.html