Hot questions for Using Glide in image

Question:

Hi im using Glide to load image from my drawable folder and all works fine, this is my code :

Glide.with(this).load(R.drawable.my_drawable_image_name).into(myImageView);

i'm wondering if there is a way to load the image just by name , something like :

Glide.with(this).load(my_drawable_image_name).into(myImageView);

because i want to get the image name dynamically ,for example from a database...

do you have any suggestion about that? thanks in advance.


Answer:

Call getImage method for get Drawable using Name only.

Glide.with(this).load(getImage(my_drawable_image_name)).into(myImageView);

public int getImage(String imageName) {

    int drawableResourceId = this.getResources().getIdentifier(imageName, "drawable", this.getPackageName());

    return drawableResourceId;
}

Question:

Right now I am using Glide-library to load the image in Android Wear. It doesn't load the image in most of the times. However, it loads image sometimes. Don't know what going wrong in my code.

Note Wear is connected to the device via Bluetooth and I successfully get JSON response of Webservice in Android Wear via Broadcast Receiver from mobile. All data are displayed properly in wear except the images.

Glide.with(mContext)
   .load("http://www.hanamoflorist.ca/images/uploads/Spring5InchesCubeVaseArrangement$45.00.jpg")
      .listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            Log.e("exception in image", "" + e);
            Toast.makeText(mContext, "" + e, Toast.LENGTH_LONG).show();
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            return false;
        }
    }).error(R.drawable.ic_placeholder_image)
        .into(((ItemViewHolder) holder).ivCardImage);

Answer:

I think you should use, DaVinci for image loading in Wearable,

DaVinci.with(context).load("Your Url").into(imageView);

Make sure you use the same playservices version as the library,

You will be able to integrate the same by adding this to your gradle:

wear :

compile ('com.github.florent37:davinci:1.0.3@aar'){
    transitive = true
}

Mobile:

compile ('com.github.florent37:davincidaemon:1.0.3@aar'){
     transitive = true
}

Hope you will get what you want.

Question:

I have an issue. I use Glide 3.8.0.

I need to download image from server and put it to a marker on google maps.

    Glide.with(getBaseActivity())
                .load(place.getIconUrl())
                .asBitmap()
                .fitCenter()
                .into(new SimpleTarget<Bitmap>(50,50) {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        map.addMarker(new MarkerOptions()
                                .icon(BitmapDescriptorFactory.fromBitmap(resource))
                                .position(place.getLatLng()));
                    }

                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        map.addMarker(new MarkerOptions()
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_marker_default_logo))
                        .position(place.getLatLng()));
                    }
                });

Also, i have default logo if some loading error, its size 50x50.

I test loading on 2 devices - nexus 5 and no name device (i dont know screen resolution and screen size, but size is almost same as nexus 5)

On the different device i have different size of marker logo and i experiment with

.into(new SimpleTarget<Bitmap>(50,50) sizes

Nexus 5, 50x50 very smaller comparing with default logo, 75x75 is smaller then default, 150x150 same as default

No name device: 75x75 same as default logo, 50x50 smaller then default

So, what can i do with Glide to make it same on the different device and as same as default logo 50x50 (default logo looks same on the different devices)


Answer:

 Glide.with(this).load("url").listener(object : RequestListener<Drawable> {
        override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {


          return true
        }

        override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
            callmethod(resource)     //pass drawable to your method and set the drawable for marker there
            imageSource=resource
            return true
        }

    })

using

  BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(convertToBitmap(d,100,100));
  MarkerOptions markerOptions = new MarkerOptions()
            .position(latLng).icon(icon)
            .title(getString(titleResId))
            .draggable(true);

also for getting the bitmap from drawable

 public Bitmap convertToBitmap(Drawable drawable, int widthPixels, int heightPixels) {
    Bitmap mutableBitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(mutableBitmap);
    drawable.setBounds(0, 0, widthPixels, heightPixels);
    drawable.draw(canvas);

    return mutableBitmap;
}

or you can use just

public Bitmap getBitmapFromURL(String strURL) {
    try {
        URL url = new URL(strURL);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

Question:

I want to use Glide to eagerly download images and cache them on disk for a future use. I want to call this functionality from a background thread.

I've read Glide's caching documentation, but it doesn't explain how to download the image without having an actual target right now. Then I found this issue and tried to use a similar approach, but whatever I try I get this exception:

java.lang.IllegalArgumentException: You must call this method on the main thread

So, how can I tell Glide to cache an image from a background thread?

EDIT: I really want to call Glide's methods on background thread. I know that I can use Handler and other ways to offload it to UI thread, but that's not what I'm asking.


Answer:

GlideApp.with(context)
    .downloadOnly()
    .diskCacheStrategy(DiskCacheStrategy.DATA) // Cache resource before it's decoded
    .load(url)
    .submit(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
    .get() // Called on background thread

Question:

I have an imageview and I would like to load an image with Glide into it. The thing here is, I want all the images have the same height (width match_parent) according to the 16:9 aspect ratio.

<ImageView
  android:id="@+id/thumbImage"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:adjustViewBounds="true"
  android:contentDescription="@string/thumbnail_text"
  android:scaleType="fitCenter"
  android:src="@drawable/thumbnail_default"
  android:cropToPadding="true"

  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:layout_constraintBottom_toTopOf="@id/thumbTitle"/>

Glide code

Glide.with(mThumb.getContext())
          .load(getThumbUrl())
          .into(mThumb);

When I load an image with aspect ratio 16:9, everything is great. However, when I load another image, the height adjusts to the height of the image.

I tried adding Constraint layout dimension ratio

app:layout_constraintDimensionRatio="16:9"

I tried playing around with adjustViewBounds and scaleType but no success.

So I think I should play with Glide to adjust the bitmap before loading it to the imageview but I couldn't find a tutorial about that.

How can I show image with width match_parent and height calculated as aspect ratio 16:9?

Thank you,

Note: I tried

<ImageView
                android:id="@+id/thumbImage"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:adjustViewBounds="true"
                android:contentDescription="@string/thumbnail_text"
                android:scaleType="centerCrop"
                android:src="@drawable/thumbnail_default"
                android:cropToPadding="true"
                app:layout_constraintDimensionRatio="H,16:9"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toTopOf="@id/thumbTitle"/>

It works, but then if the orientation is changed, the height goes 0.


Answer:

One way around is to use a Image view with 16:9 ratio .

public class CustomImageView extends AppCompatImageView {
    public CustomImageView(Context context) {
        super(context);
    }

    public CustomImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int width = getMeasuredWidth();
        int height=(width * 9) / 16;
        setMeasuredDimension(width, height);
    }
}

This will make a ImageView with hard code ratio of 16/9 . You can use Custom attributes for it to make it more flexible.

Question:

Am using Glide version 4.8.0

And for loading an image I do this

GlideApp
    .with(HomePageFragment.this)
    .load(remoteURL)
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .into(mImageView);

When the device is connected to Internet the image loades successfully but when device goes offline, how to load the same image from cache that was already featched from the remoteURL?

My CustomAppGlideModule looks like this

@GlideModule
public class CustomAppGlideModule extends AppGlideModule {

    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        builder.setMemoryCache(new LruResourceCache(20 * 1024 * 1024));
        builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 100 * 1024 * 1024));
    }

}

I also tried

.onlyRetrieveFromCache(true)

But that also does not help.


Answer:

Option 1: Use DiskCacheStrategy.SOURCE instead of DiskCacheStrategy.ALL it should work because of DiskCacheStrategy.SOURCE saves the original data to cache.

//Version 4.x
GlideApp
    .with(HomePageFragment.this)
    .load(remoteURL)
    .diskCacheStrategy(DiskCacheStrategy.DATA)
    .into(mImageView);

//Version 3.x
Glide.with(mContext)
   .load(url)
   .diskCacheStrategy(DiskCacheStrategy.SOURCE)
   .into(imageView);

Option 2: (if above does not work)

Any specific reason for using Glide? Would you like to give a shot to Picasso, I found Picasso much better for this. You may use the following code for offline caching. It will first serve from offline if not found then search for online image.

Picasso.with(getActivity())
.load(imageUrl)
.networkPolicy(NetworkPolicy.OFFLINE)
.into(imageView, new Callback() {
    @Override
    public void onSuccess() {
      //..image loaded from cache
    }

    @Override
    public void onError() {
        //Try again online if cache failed
        Picasso.with(getActivity())
                .load(posts.get(position).getImageUrl())
                .error(R.drawable.header)
                .into(imageView, new Callback() {
            @Override
            public void onSuccess() {
              //... image loaded from online
            }

            @Override
            public void onError() {
                Log.v("Picasso","Could not fetch image");
            }
        });
    }
});

Question:

I have a problem that each time , I take a photo and and I try to display it. Glide load me the old file. I check the file locally , it has been changed successfully. But the old image is displayed.

This is my code :

  public void onCameraCaptureCompleted(final File photoFile) {
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                stopCamera();
                pickedImg.setImageBitmap(null);
                Glide.with(TakePhotoFragment.this)
                        .load(photoFile)
                        .asBitmap()
                        .dontAnimate()
                        .diskCacheStrategy(DiskCacheStrategy.NONE)
                        .into(pickedImg);
            }
        });

    }

Who knows how to solve this problem ?


Answer:

Try with skipMemoryCache

Allows the loaded resource to skip the memory cache.

.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)   

NOTE

If same problem still coming then use clearMemory(). For good approach, Create Application Class and add this

public class RootApplication extends Application 
{
   @Override public void onLowMemory() {
    super.onLowMemory();
    Glide.get(this).clearMemory();
}

Make sure, added this Application class in Manifest.

<application
    android:name=".RootApplication"
 >

Question:

I searched everywhere but since Glide has released version 4.4. I can not find a way to apply RoundedCornersTransformation any more. I am using glide-transformations and there is not a correct solution available even on their Github forum as well.

Previously:

GlideApp.with(context)
.load(url)
.transforms(new CenterCrop(), new RoundedCorners(radius))
.into(imageView);

Then with an update it has to be called like this:

Glide.with(context)
   .load(url)
   .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(radius)))
   .into(imageView);

But with Glide 4.4 I am facing an issue that :

1: Transformation is not applied at all.

2: if I try to use the .transforms API it seems like it is not available anymore!

Please reply if anyone can help. I will post my reply if found one!


Answer:

Here is what I read on the github opened issues of the project.

you can use Glide's RoundedCorners transformation. And please note that centerCrop() is overriding previous transformations. So you can use:

 Glide.with(context)
   .load(url)
   .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(radius)))
   .into(imageView);

But unfortunately Glide has no transforms() but has only transform() method.

Hence, I checked my code and found that in my ImageView I was using:

android:scaleType="centerCrop"

As a result my Transform was being overridden by this property, just what is mentioned in the comment from the forum above.

centerCrop() is overriding previous transformations

Final Solution: I removed scaleType="centerCrop" from ImageView in layout xml and wrote my code as such.

RequestOptions options = new RequestOptions();
                options.placeholder(R.drawable.place_holder)
                        .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                        .error(R.drawable.error_place_holder)
                        .transform(new CenterCrop())
                        .transform(new RoundedCorners(corner_size));

                Glide.with(mActivity).load(url)
                        .apply(options)
                        .into(image_view);

Voila! It worked!

Note: centerCrop() may work differently for different use cases.

Question:

I want to show the image using Glide animation. I'm downloading this image from the server. The animation is working fine when it downloads from the server but it's not working when the image is taken from Glide cache

requestOptions.skipMemoryCache(true);
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);

Please check my code below

RequestOptions requestOptions = new RequestOptions();
requestOptions.timeout((int) NetworkParam.CONNECTION_TIME_OUT);
requestOptions.placeholder(R.drawable.img_blue_shirt);
requestOptions.priority(Priority.HIGH);
requestOptions.signature(new ObjectKey(String.valueOf(imgName)));
//requestOptions.skipMemoryCache(true);
requestOptions.diskCacheStrategy(DiskCacheStrategy.NONE);

//requestOptions.error(R.drawable.img_blue_shirt);
try {
    Glide.with(imageView.getContext().getApplicationContext())
         .load(imgUrl)
         .transition(GenericTransitionOptions.with(R.anim.anim_slide_in_left))
         .apply(requestOptions)
         .into(imageView);
} catch (Exception ex) {
    ex.printStackTrace();
}

Answer:

According to the documentation here, in Glide v4 you can implement and apply a custom TransitionFactory.

For always crossfading, in Kotlin you can:

  1. Implement the TransitionFactory interface
class DrawableAlwaysCrossFadeFactory : TransitionFactory<Drawable> {
  private val resourceTransition: DrawableCrossFadeTransition = DrawableCrossFadeTransition(300, true) //customize to your own needs or apply a builder pattern
  override fun build(dataSource: DataSource?, isFirstResource: Boolean): Transition<Drawable> {
    return resourceTransition
  }
}
  1. Apply it as a transition
GlideApp.with(this)
  .load(url)
  .transition(DrawableTransitionOptions.with(DrawableAlwaysCrossFadeFactory()))
  .into(image)

Question:

I have several RecyclerView's inside my app, and all of them have items which have an ImageView, which are further populated with Glide, like this:

Glide.with(context)
 .load(imageUrl)
 .asBitmap()
 .error(R.drawable.placeholder_avatar)
 .centerCrop()
 .into(mAvatarImageView);

In my Preference screen, users can disable loading of all remote images to save bandwidth. What's the best way to tell Glide not to load images, without using a classic if-else conditions inside all RecyclerView adapters, which violates the DRY principle?

I'm looking for a method like this:

.shouldLoad(UserSettings.getInstance().isImageLoadingEnabled());

Answer:

Assuming you are using Glide v4, there is a request option specifically designed for this purpose: RequestOptions.onlyRetrieveFromCache(boolean flag). When enabled, only resources already present in memory or disk cache are loaded, effectively preventing loads from the network and saving bandwidth.

If you use Glide v4 Generated API, this option is directly available on the GlideRequest returned by GlideApp.with(context).asBitmap(). Otherwise, you have to create a RequestOptions with this flag enabled and apply it :

RequestOptions options = new RequestOptions().onlyRetrieveFromCache(true);
Glide.with(context).asBitmap()
    .apply(options)
    .error(R.drawable.placeholder_avatar)
    .centerCrop()
    .into(mAvatarImageView);

Question:

I am creating a React Native native UI Component. It is an image gallery that requires loading images from URL. In my PageAdapter, I am loading the image using the following code but the image is not loading.

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

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
            Log.i("ImageLoader", "Successfully loaded");
            return false;
        }
    }).override(720, 1280).into(imageView);

The onResourceReady method is always hitting but no image is loading. How do I solve this?


Answer:

Try using:

Glide.with(context)
        .asBitmap()
        .load(url)
        .into(new CustomTarget<Bitmap>(720,1280) {
            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                imageView.setImageBitmap(resource);
            }

            @Override
            public void onLoadCleared(@Nullable Drawable placeholder) {
            }
        });  

and make sure you are using the latest version

implementation 'com.github.bumptech.glide:glide:4.9.0'

Question:

Actually I'm trying to load images into my reycycleview using glide 4.4.0 and it's loading fine . But now the problem is my recyclerview is lagging a bit when I scroll fast due to the image loading . But I saw some of the glide's method called preload and downloadOnly .So,my question is are these methods helpful for loading image in advance if so then how to use them?


Answer:

You can use this to fine-tune your preloading. It requires quite a bit of work but looks promising.

In short, you need to create a PreLoader class that will get image URLs from your data set:

private class MyPreloadModelProvider implements PreloadModelProvider {
    @Override
    @NonNull
    public List<U> getPreloadItems(int position) {
      String url = myUrls.get(position);
      if (TextUtils.isEmpty(url)) {
        return Collections.emptyList();
      }
      return Collections.singletonList(url);
    }

    @Override
    @Nullable
    public RequestBuilder getPreloadRequestBuilder(String url) {
        return 
            GlideApp.with(fragment)
              .load(url) 
              .override(imageWidthPixels, imageHeightPixels);
    }
}

And then you set it as a scroll listener on your recycler view:

PreloadSizeProvider sizeProvider = 
    new FixedPreloadSizeProvider(imageWidthPixels, imageHeightPixels);
PreloadModelProvider modelProvider = new MyPreloadModelProvider();
RecyclerViewPreloader<Photo> preloader = 
    new RecyclerViewPreloader<>(
        Glide.with(this), modelProvider, sizeProvider, 10 /*maxPreload*/);

RecyclerView myRecyclerView = (RecyclerView) result.findViewById(R.id.recycler_view);
myRecyclerView.addOnScrollListener(preloader);

After this, you'll get your images preloaded before the onBondViewHolder callback in the adapter, and you'll be able to display them from the cache.

@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
  ImageView imageView = ((MyViewHolder) viewHolder).imageView;
  String currentUrl = myUrls.get(position);

  GlideApp.with(fragment)
    .load(currentUrl)
    .override(imageWidthPixels, imageHeightPixels)
    .into(imageView);
}

Question:

I am generating a PDF file using the native PDF Libraries (android.graphics.pdf.PdfDocument)

the document should contain a header that is a static imageView, a few textviews, and a RecyclerView with a bunch of images,

everything except the recyclerview is displayed correctly,

the recyclerview is using the Glide library to load the images but they are not loaded nor displayed, I tried pre-fetching them using the library but it also does nothing,

here is the code for creating the pdf

    public File createPDF(PostDB postDB) {
    int addition = 0;
    String postDBContent = postDB.getContent();
    if (postDBContent != null) {
        int estimatedLineCount = postDBContent.length() / 43;
        String[] lines = postDBContent.split("\r\n|\r|\n");
        estimatedLineCount += lines.length;
        addition = (estimatedLineCount - 43) * 60;
    }


    List<String> imagesUrls = postDB.getImagesUrls();
    for (String url : imagesUrls) {
        Glide.with(context).load(url).preload();
    }


    try {
        FileOutputStream fOut = context.openFileOutput(LOCAL_PATH, Context.MODE_PRIVATE);
        PdfDocument document = new PdfDocument();
        PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(1800, 3900 + addition + 1000, 1).create();
        PdfDocument.Page page = document.startPage(pageInfo);
        Canvas canvas = page.getCanvas();
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View content;
        if (inflater != null) {
            final int[] count = {0};
            content = inflater.inflate(R.layout.pdf_layout, null);
            ButterKnife.bind(this, content);
            publisherTextView.setText(postDB.getAuthor());
            Date date = new Date(postDB.getDate());
            DateFormat dateFormat = DateFormat.getInstance();
            String format = dateFormat.format(date);
            dateTextView.setText(format);
            titleTextView.setText(postDB.getTitle());
            contentPreviewTextView.setText(postDBContent);
            recyclerViewImages.setLayoutManager(new GridLayoutManager(context, 2));
            recyclerViewImages.setAdapter(new PDFImageAdapter(postDB.getImagesUrls()));
            String text = postDB.getCity() + ", " + postDB.getCountry();
            location.setText(text);
            int measureWidth = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getWidth(), View.MeasureSpec.EXACTLY);
            int measuredHeight = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getHeight(), View.MeasureSpec.EXACTLY);
            content.measure(measureWidth, measuredHeight);
            content.layout(0, 0, page.getCanvas().getWidth(), page.getCanvas().getHeight());
            content.draw(canvas);

        }
        document.finishPage(page);
        document.writeTo(fOut);
        document.close();
        fOut.close();
        return new File(context.getFilesDir().getPath() + "/" + LOCAL_PATH);
    } catch (IOException e) {
        Log.i("error", e.getLocalizedMessage());
        return null;
    }
}

here is my code for binding the ViewHolders

 public void setData(String url) {
    Glide.with(imageView.getContext()).load(url)
            .listener(new RequestListener<Drawable>() {
                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                    Timber.d("onLoadFailed");
                    return true;
                }

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

the data onBind method is called, and calls the setData method. but neither callback from Glide is ever called.


Answer:

I use the iText library to solve this,

here is code I use to add images for example. that way you dont need any views.

Rectangle pageSize = PageSize.A4;
Document document = new Document();
PdfWriter.getInstance(document, context.openFileOutput(LOCAL_PATH, Context.MODE_PRIVATE));
document.open();
 document.setPageSize(pageSize);
   document.addCreationDate();
   document.addAuthor(context.getString(R.string.pdf_creator));
   document.addCreator(context.getString(R.string.pdf_creator));
Image image = Image.getInstance(filename);
   image.scaleToFit(300f, 150f);
   image.setAbsolutePosition(absoluteX, absoluteY);
   document.add(image);
document.close();

Question:

I'm trying to load an image using Glide:

case "image":
    Log.d("TRecyViewAdapter", "Got Image");
    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new    GridLayoutManager.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.MATCH_PARENT
    ));
    contents.addView(imageView);
    Glide.with(context).load(part.getContent()).into(imageView);
    break;

It's showing nothing.

However if I change that last line to Picasso:

    Picasso.with(context).load(part.getContent()).into(imageView);

Image loads at full size just as I was expecting.

Also. If I use Glide with a placeholder:

    Glide.with(context).load(part.getContent()).placeholder(R.mipmap.def_avatar).into(imageView);

It loads the image but in a very small size (the size of R.mipmap.def_avatar)

I want to be able to load the real size image without having to specify placeholders (its a dynamic view and its supposed to show a lot of different images with different sizes and so)

I want to use Glide instead of Picasso because I want support for animated gifs.


Answer:

Looks like adding override does the trick. Image is now loading as expected.

Glide.with(context).load(part.getContent()).override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).into(imageView);

Question:

How do I set background image for text with glide?

file[0] = "mnt/sdcard/sort_icon.png"


SimpleTarget target = new SimpleTarget<Drawable>(){
                    @Override
                    public void onResourceReady(Drawable resource, GlideAnimation<? super Drawable> glideAnimation) {
                        txtView.setBackground(resource);
                    }
                };
                Glide.with(getBaseContext())
                        .load(file[i-4])
                        .into(target);

Answer:

Solution:

Try this:

Add the implementation in your gradle(app):

dependencies {
    .....
    .....

    def glide = "4.8.0"

    // Glide
    implementation "com.github.bumptech.glide:glide:$glide"
    annotationProcessor "com.github.bumptech.glide:compiler:$glide"
    .....
}

Then, in your Activity/Fragment:

File file = new File(file[i-4]);
Uri imageURI = Uri.fromFile(file);

Glide.with(MainActivity.this)
     .load(imageURI)
     .apply(RequestOptions.placeholderOf(R.drawable.ic_launcher))
     .into(new SimpleTarget<Drawable>() {
          @Override
          public void onResourceReady(@NonNull Drawable resource, 
                      @Nullable Transition<? super Drawable> transition) {

                     txtView.setCompoundDrawablesWithIntrinsicBounds(resource, null, null, null);

                }
            });

See if it works.

Question:

I have a list of a post using recyclerview. The list are great, but problem come when I try to add an image at the recyclerview. I'm using Glide to add the images. I have successed adding image using glide at Navigation Drawer, but when i try at Recyclerview it show nothing than the default image i sourced.

This is my kotlin,

class InformationListActivity : MainActivity() {
private val glide: RequestManager? = null

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_information_list)

    val toolbar = findViewById<View>(R.id.toolbar) as Toolbar
    setSupportActionBar(toolbar)
    supportActionBar!!.setDisplayHomeAsUpEnabled(true)
    supportActionBar!!.setDisplayShowHomeEnabled(true)

    val user = FirebaseAuth.getInstance().currentUser
    val uName = user?.displayName
    val uEmail = user?.email
    val uPhotoUrl = user?.photoUrl
    user?.uid

    val navigationView = findViewById<View>(R.id.nav_view) as NavigationView
    navigationView.setNavigationItemSelectedListener(this)
    val headerView = navigationView.getHeaderView(0)

    val navName = headerView.findViewById<TextView>(R.id.navName)
    navName.text = uName
    val navEmail = headerView.findViewById<TextView>(R.id.navEmail)
    navEmail.text = uEmail
    val navImage = headerView.findViewById<ImageView>(R.id.navImage)
    Glide.with(this).load(uPhotoUrl).into(navImage)

    window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)

    val signOut = findViewById<View>(R.id.btnSignOut) as LinearLayout
    signOut.setOnClickListener {
        FirebaseAuth.getInstance().signOut()
        val goToLogin = Intent(this@InformationListActivity, LoginActivity::class.java)
        startActivity(goToLogin)
    }


    val recyclerView = findViewById<View>(R.id.recycler_view) as RecyclerView
    recyclerView.setHasFixedSize(true)
    recyclerView.layoutManager = LinearLayoutManager(this)
    val myref = FirebaseDatabase.getInstance().reference.child("/posts")
    val recyclerAdapter = object : FirebaseRecyclerAdapter<Post, InformationListActivity.PostViewHolder>(
            Post::class.java,
            R.layout.information_model,
            InformationListActivity.PostViewHolder::class.java,
            myref
    ) {
        override fun populateViewHolder(viewHolder: InformationListActivity.PostViewHolder, model: Post, position: Int) {
            val data_empty = findViewById<View>(R.id.data_empty) as TextView
            data_empty.visibility = View.GONE
            viewHolder.run {
                glide?.let { setmPostImageUrl(it,model.getmPostImageUrl()) }
                setmPostTitle(model.getmPostTitle())
                setmPostDescription(model.getmPostDescription())
                viewHolder.setItemClickListener(object : ItemClickListener {
                    override fun onItemClick(pos: Int) {
                        //OPEN DETAIL ACTIVITY
                        openInformationDetail(model.getmPostImageUrl(), model.getmPostTitle(), model.getmPostDescription())
                    }
                })
            }
        }
    }
    recyclerView.adapter = recyclerAdapter
}

private fun openInformationDetail(vararg details: String) {
    val i = Intent(this, InformationDetailActivity::class.java)
    i.putExtra("POSTIMAGEURL_KEY", details[0])
    i.putExtra("POSTTITLE_KEY", details[1])
    i.putExtra("POSTDESCRIPTION_KEY", details[2])
    startActivity(i)
}

class PostViewHolder(mView: View) : RecyclerView.ViewHolder(mView), View.OnClickListener {
    private var modelImgPost: ImageView = mView.findViewById(R.id.imgPost)
    private var modelPostTitle: TextView = mView.findViewById(R.id.modelPostTitle)
    private var modelPostDescription: TextView = mView.findViewById(R.id.modelPostDescription)
    private var btnMore: Button = mView.findViewById(R.id.btnMore)
    private lateinit var itemClickListener: ItemClickListener

    init {
        btnMore.setOnClickListener(this)
    }

    fun setItemClickListener(itemClickListener: ItemClickListener) {
        this.itemClickListener = itemClickListener
    }

    override fun onClick(view: View) {
        this.itemClickListener.onItemClick(this.layoutPosition)
    }

    fun setmPostImageUrl(glide: RequestManager, mPostImageUrl: String) {
        glide.load(Uri.parse(mPostImageUrl)).into(modelImgPost)
    }

    fun setmPostTitle(mPostTitle: String) {
        modelPostTitle.text = mPostTitle
    }

    fun setmPostDescription(mPostDescription: String) {
        modelPostDescription.text = mPostDescription
    }
}

Answer:

if (glide != null) {
    setmPostImageUrl(glide, model.getmPostImageUrl())
}

Glide is null because you never assign / instantiate it.

Replace this line:

private val glide: RequestManager? = null

with:

private var glide: RequestManager? = null

and in onCreate() do:

glide = Glide.with(this)

Question:

I have simple layout with ImageView

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.vbusovikov.glidetest.MainActivity">

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        />

</RelativeLayout>

And simple Glide expression to load an image to this ImageView just to test Glide

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView imageView = (ImageView)findViewById(R.id.image);

        Glide.with(this)
                .load("http://you-ps.ru/uploads/posts/2013-08/1376601606_1273.png")
                .error(R.mipmap.ic_launcher)
                .into(imageView);

    }

However, error icon is shown. What kind of problem it can be? I have proxy server on my network, and appropriate gradle.properties for that case.

systemProp.http.proxyHost=proxy******.ru
systemProp.http.proxyPort=****

But even if i try to launch this little app outside of any proxies, it won't work for some reason.

My build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.vbusovikov.glidetest"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'

    compile 'com.github.bumptech.glide:glide:3.7.0'

    testCompile 'junit:junit:4.12'
}

UPD. This simple app can load pictures from internet, but it cannot load pictures from my server. Some pictures of my server are being loaded fine, but others are not. I'm lost with this already


Answer:

Use https insted of http in your image url.

Question:

i have a strange Problem while using Glide as below

I cannot Load Images From Nginx server

Glide.with(getApplicationContext()).load("https://www.thehellofood.com/uploads/food_categories_images/Tandoori_Starters.jpg").into(holder.mImageView); 

But When i use Images fro Some Other Server I can Load them

Glide.with(getApplicationContext()).load("https://ichef-1.bbci.co.uk/news/660/cpsprodpb/11E4D/production/_92839237_001474558-1.jpg").into(holder.mImageView);

whats the difference between these two images do sever has any effect on Loading Images


Answer:

Upon inspecting with your image link in Glide, I found the error to be because of signing the server security with Self-signed certificate (making it HTTPS) and server configuration. The exact error would be:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

See if this helps. https://stackoverflow.com/a/41114813/6720181

Question:

I use glide version 4.7.1 I wanna use default image when onLoadFailed.

this is my code

Glide.with(context).load(imageUrl).listener(new RequestListener<Drawable>() {
    @Override
    public boolean onLoadFailed(@Nullable GlideException e, Object model, com.bumptech.glide.request.target.Target<Drawable> target, boolean isFirstResource) {
        // fail
        // How can i use default image in imgvAssetPicture?
    }

    @Override
    public boolean onResourceReady(Drawable resource, Object model, com.bumptech.glide.request.target.Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
        // success
        imgvLoadingProgressbar.setVisibility(View.INVISIBLE);
        imgvAssetPicture.setVisibility(View.VISIBLE);
        return false;
    }
}).into(imgvAssetPicture);

Answer:

 Glide.with(passContext)
.applyDefaultRequestOptions(new RequestOptions()
.placeholder(R.drawable.ic_user_default)
.error(R.drawable.ic_user_default))
.load(url)
.into(image);

With version 4.7.1 (you are using), you can easily set these options.

  • placeHolder which shows when there is not image.
  • error when some URL fails to load.

Bonus

Are you using some ProgressBar with setting visibility, that's very old way to do.

See CircularProgressDrawable, which is very easy to use. Just pass this CircularProgressDrawable in your placeHolder.

Question:

I am trying to load an image from a URL into my imageview using glide but it is not working. I cannot download and display the image. I have added all the dependencies and permissions in my project but still it doesn't seem to work.Any idea whats going wrong? Here are all the files I have in my project.The strange thing is I'm not getting any kind of error or exception in my logs

////MainActivity.java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_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gPMpQhQ3yQoQwZ4oMMZcgQH2QoQ4b4IEMZMsQHGcqQIT7IUIYM8UGGMr/PUFXAVPWVvCoT12USYj++4FVroazwCgu6TULshSrqlA3gL/9dZjv3BcyTEuoStnACoOjzxbJjcmhETg8aQAmAQnPrBz/MO4PCk4cpI3IN+EJQt7i2J45J21GsnjTYSN/F4x7Bivie7cZF8rxQdr4TjQZrDBlQT8l2UZWxlUz1EtLy+FLlhbERigwvPSbHZc8dDpZLp2nc/xJ/AMM4nGaREA01AAAAAElFTkSuQmCC";

    ImageView imageView = (ImageView) findViewById(R.id.imageView);

    Glide.with(this)
            .load(imgUrl)
            .into(imageView);
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.banty.gallaryapp.MainActivity">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="400dp"
    android:layout_height="400dp"
    android:layout_centerInParent="true"
    />
</RelativeLayout>

My Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.banty.gallaryapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

dependencies in build.gradle

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
// RecyclerView
compile 'com.android.support:recyclerview-v7:23.1.1'

// volley
compile 'com.android.volley:volley:1.0.0'

// Glide
compile 'com.github.bumptech.glide:glide:3.7.0'
}

Answer:

Instead of your image url, try with this (I removed the fist part, before the actual encode):

String imgBase64 = "iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAb1BMVEX///+ZzACTyQCRyQDi8MTk8cu+33f2+u3N5piczRSu2EnA4Hr+//rE4oTr9tXy+eOo1Dr1+unS6KOi0Sey2Fvt9tvd7ru322jb7bb6/PPE4oa73XHK5JLr9dfW6q32+uuo1DzQ6KC02mCv11LH4oz7JUSRAAAGUUlEQVR4nO2d63qiMBBASYK2eBcEReul6vs/4wJuEcJEg+Yy3Z3zc7fhyyEjl2TIBAFB/D/ELFmaOtZZrE0dyhy5YDwxdKytYGJj6Fjm+BCM8S8jh9oXh0JoGEx50a+5iSNFjDFT4WAUUx0zd6pMszcTp4YOYwUzJx9tjJaY6BzeGC0xEGCYY7Rk+/YAoI7Rknc7iDtGS6ogu77cfIY8RkuqOE07/5zPB+Hh+7qdlmyvn4dskH50W6OP0RKpk5PZYbtKuBBcpvin6DKNBw1R/DFakt7jdLkZJ6UaU1OasnW8r/6+itFPn53X42+chlMmHrm1PAVfb/KA/YYYLUmKjkbs4dCBlmU7/DFaEvZ0azL23XkN0vUbgowvMt8CT5ivxBt+JSLC7Jjv3vWrHBcz3yIq4r5XF6XjOvftArE8GfJj5W0S4TTNwUSA3hEr30Iya7OCxTAyVLfGPDEXoTUC0UV1bl6vUkTzjJpaGMCb4tS32g1rglgU5/YEC8XX5wuMkQP9Kt6GuPar0+MmIvYtWL0rSZ2NDsfiASDuJXhNi5OVLbqOYuBZsPsmweulv4v2MCY/Uxmf3dsqP3pSuwE8yTQeRka6hpO6yVf3rHh97V8Cp3zy8L8hRNg4JBD1Pi+op253W905axlGzSYH4Kfo720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