通过Glide图像质量差

时间:2016-05-03 18:48:39

标签: android android-drawable android-bitmap android-glide

我需要从网址下载图片,然后将其作为我的RelativeLayout的背景。 图像(jpeg)大小约为10kb,具有良好的质量和分辨率。但是当我尝试使用Glide下载图像时,它看起来是压缩的(请参见下面屏幕上的背景图像)。

enter image description here

Glide.with(this)
            .load("url...")
            .asBitmap()
            .format(DecodeFormat.PREFER_ARGB_8888)
            .into(new SimpleTarget<Bitmap>(rootViewWidth, rootViewHeight) {
                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    Drawable drawable = new BitmapDrawable(resource);
                    rootView.setBackground(drawable);
                }
            });

我该如何改进?

谢谢!

1 个答案:

答案 0 :(得分:0)

Glide默认位图格式设置为RGB_565,因为它只消耗了50%的内存占用但是picaso的位图格式是ARGB_8888 ..

您可以通过创建一个从GlideModule扩展的新类来将位图格式切换为ARGB_8888:

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.
}

}

然后将其定义为AndroidManifest.xml中的元数据

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

现在看起来好多了!

一切顺利:)

if u have any doubt please refer this Article

相关问题