lawloretienne / ImageGallery

A gallery used to host an array of images
Apache License 2.0
645 stars 116 forks source link

Unable load Image with Glide Library #14

Closed ledangtuanbk closed 8 years ago

ledangtuanbk commented 8 years ago

Hi Team. For some reason, I want to use Glide library to load image instead of Picasso as your example. When I used Glide, The image not able to load Image.

My code like that:

public void loadFullScreenImage(final ImageView iv, final String imageUrl, int width, final LinearLayout bgLinearLayout) { Log.d(TAG, "loadFullScreenImage: " + imageUrl); Glide.with(iv.getContext()).load(imageUrl).into(iv); } else { iv.setImageDrawable(null); } } Please help me to do it. Thank you very much.

sushant23 commented 8 years ago

+1

davidpini commented 8 years ago

+1

Hitexroid commented 8 years ago

+1

lawloretienne commented 8 years ago

So I just tried this for Glide integration and it works.

@Override
public void loadFullScreenImage(final ImageView iv, String imageUrl, int width, final LinearLayout bgLinearLayout) {
    if (!TextUtils.isEmpty(imageUrl)) {
        SimpleTarget target = new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(final Bitmap bitmap, GlideAnimation glideAnimation) {
                Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
                    public void onGenerated(Palette palette) {
                        applyPalette(palette, bgLinearLayout);
                        iv.setImageBitmap(bitmap);
                    }
                });
            }
        };

        Glide.with(iv.getContext())
                .load(imageUrl)
                .asBitmap()
                .override(width, width)
                .into(target);
    } else {
        iv.setImageDrawable(null);
    }
}