Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strange behaviour when upscaling image using CENTER_OUTSIDE DownsampleStrategy #2459

Closed
Zhenek1 opened this issue Oct 9, 2017 · 1 comment
Labels
Milestone

Comments

@Zhenek1
Copy link

Zhenek1 commented Oct 9, 2017

Glide Version: 4.2.0

Device/Android Version: Nexus 5 API 23

Issue details / Repro steps / Use case background:

I am trying to use CENTER_OUTSIDE DownsampleStrategy, which is default, in combination with ImageView's scaleType set to center. When the source width and height are greater than ImageView's, result image is downscaled correctly, but when the source width and height are smaller, the result values are not as expected. For example, when trying to load 3000x5000 image into 500x500 ImageView i get 833x500 downscaled image, but when loading 200x200 image into the same view i get 429x429 image as a result (expected 500x500 image in that case). My guess is that these values come from adjustTargetDensityForError method which can produce maxInt value in the case of upscaling and the resulting scale value becomes roughly 2.147.
My question is whether this behavior is correct or not?

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

I check result bitmap size using listener's resource mBitmapWidth and mBitmapHeight

Glide.with(this)
             .load(url)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        return false;
                    }
                })
                .into(imageView);

Simple activity with layout and hardcoded ImageView size in px for testing purposes.

Layout XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.zhenek.myapplication.MainActivity">

    <ImageView
        android:layout_gravity="center"
        android:id="@+id/image"
        android:layout_width="500px"
        android:layout_height="500px"
        android:scaleType="center"/>

</FrameLayout>
@sjudd sjudd added the bug label Oct 9, 2017
@sjudd sjudd added this to the 4.3 milestone Oct 9, 2017
@sjudd
Copy link
Collaborator

sjudd commented Oct 10, 2017

Thanks for filling out the issue template and providing an awesome level of detail. You're exactly right, there's a bug in that method that causes us to use 2.147 as the multiplier whenever we're using a DownsampleStrategy that upscales with an image that's smaller than the requested dimensions.

I've got a fix for it internally and will hopefully get it synced out today.

@sjudd sjudd closed this as completed in c7383b2 Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants