Glide: How to resize image and set scale type to FitXY?

Created on 25 May 2017  Â·  6Comments  Â·  Source: bumptech/glide


Glide Version:4.0.0-RC0


Integration libraries: NO


Device/Android Version:


Issue details / Repro steps / Use case background:

Need to load all gallery photos to my app, so i am using Glide.
Glide load line / GlideModule (if any) / list Adapter code (if any):


RequestOptions requestOptions = new RequestOptions();
            requestOptions.placeholder(R.drawable.logo2);
            requestOptions.fitCenter();

Glide.with(PhotosScreen.this)
                    .applyDefaultRequestOptions(requestOptions)
                    .load(new File(photosList.get(position)))
                    .into(holder.my_image_view);


Layout XML:

<FrameLayout xmlns:android="...


Stack trace / LogCat:

paste stack trace and/or log here


I need to fetch all photos from gallery and display it to app. Need to display photos in grid of 3 columns.
Also need to resize image and scale with fitxy.

question stale

Most helpful comment

@pinvisible it should be as simple as:

Glide.with(PhotosScreen.this)
        .load(new File(photosList.get(position)))
        .apply(new RequestOptions()
                .placeholder(R.drawable.logo2)
                //.fitCenter() // no need for this
        )
        .into(holder.my_image_view) // set ImageView.scaleType to `fitXY` before the Glide load
;

or what @barnhill was referring to:

Glide.with(PhotosScreen.this)
        .load(new File(photosList.get(position)))
        .apply(new RequestOptions()
                .placeholder(R.drawable.logo2)
                .override(w, h) // set exact size
                .fitCenter() // keep memory usage low by fitting into (w x h) [optional]
        )
        .into(holder.my_image_view) // probably set ImageView.scaleType to `fitXY` so it stretches
;
// note: the final stretched/displayed size will come from layout

Also, please reconsider that requirement, I can't imagine a use case where the user might want to see a distorted image coming from their own device. It'll just make them think that there's something wrong with the original image... even though it's just the display in your app; there are so many better ways to display images.

All 6 comments

have you tried the override option to scale your image to an XY value?

How to do this? Can you please share code or link?

On Fri, May 26, 2017 at 9:26 AM, Brad Barnhill notifications@github.com
wrote:

have you tried the override option to scale your image to an XY value?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/bumptech/glide/issues/1969#issuecomment-304184782,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ATzZ5s7O0xzgx8OhgmBVZsWeUQ6hl29Cks5r9k2EgaJpZM4NmZ0x
.

@pinvisible it should be as simple as:

Glide.with(PhotosScreen.this)
        .load(new File(photosList.get(position)))
        .apply(new RequestOptions()
                .placeholder(R.drawable.logo2)
                //.fitCenter() // no need for this
        )
        .into(holder.my_image_view) // set ImageView.scaleType to `fitXY` before the Glide load
;

or what @barnhill was referring to:

Glide.with(PhotosScreen.this)
        .load(new File(photosList.get(position)))
        .apply(new RequestOptions()
                .placeholder(R.drawable.logo2)
                .override(w, h) // set exact size
                .fitCenter() // keep memory usage low by fitting into (w x h) [optional]
        )
        .into(holder.my_image_view) // probably set ImageView.scaleType to `fitXY` so it stretches
;
// note: the final stretched/displayed size will come from layout

Also, please reconsider that requirement, I can't imagine a use case where the user might want to see a distorted image coming from their own device. It'll just make them think that there's something wrong with the original image... even though it's just the display in your app; there are so many better ways to display images.

@TWiStErRob Surprisingly I can't resize the image with particular size.
All things are setup as mentioned: scaleType, wrap_content, adjust view bounds but the height of images are variable.

Edit: I was using Picasso and it resolves wrap_content, but Glide doesn't. So I've just changed my method and Glide works perfectly.

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Anyone figure out how to do this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tryking picture Tryking  Â·  3Comments

kooeasy picture kooeasy  Â·  3Comments

StefMa picture StefMa  Â·  3Comments

Morteza-Rastgoo picture Morteza-Rastgoo  Â·  3Comments

PatrickMA picture PatrickMA  Â·  3Comments