Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - image quality is low when using glide

I'm new to android developing. In my app, I have a horizontalScrollView that contains images. Later I have been using Picasso to load images from URL. Then I heard about glide so I switched to glide and now my image loading is fast but the quality of images is too low.

code below

//load image from URL 1.1
        ivImageFromURL = (ImageView) findViewById(R.id.videoconwmimage);
        Glide.with(this).load("http://imgur.com/KtfpVUb.png").into(ivImageFromURL);
like image 681
Simon Avatar asked Feb 24 '17 08:02

Simon


2 Answers

If you are using Glide v4, then when making Glide requests, change

Glide.with(imageView).load(url).into(imageView);

to

Glide.with(imageView).load(url)
    .apply(new RequestOptions()
            .fitCenter()
            .format(DecodeFormat.PREFER_ARGB_8888)
            .override(Target.SIZE_ORIGINAL))
    .into(imageView);

That did the trick for me without having to add anything to the manifest. It might help to also add android:adjustViewBounds="true" to your ImageView in XML. The classes are

import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
like image 144
Leo Aso Avatar answered Nov 09 '22 11:11

Leo Aso


This is because Glide default Bitmap Format is set to RGB_565 since it consumed just 50% memory footprint compared to ARGB_8888 used by Picasso.

you can fix it making following changes:

public class GlideConfiguration implements GlideModule {

    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        // Apply options to the builder here.
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    }

    @Override
    public void registerComponents(Context context, Glide glide) {
        // register ModelLoaders here.
    }
}

And add following to your manifest:

<meta-data android:name="com.inthecheesefactory.lab.glidepicasso.GlideConfiguration"
            android:value="GlideModule"/>

For more details visit here

like image 40
nnn Avatar answered Nov 09 '22 12:11

nnn