图片质量问题
在 Android 中有两个主要的方法对图片进行解码:ARGB8888 和 RGB565。前者为每个像素使用了 4 个字节,后者每个像素使用了 2 个字节。ARGB8888 的优势是图像质量更高以及能存储一个 alpha 通道。 Picasso使用 ARGB8888,Glide 默认使用低质量的 RGB565。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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
中将GlideModule
定义为meta-data
1
2
|
<meta-data android:name=
"com.inthecheesefactory.lab.glidepicasso.GlideConfiguration"
android:value=
"GlideModule"
/>
|
增加 Glide 的图片质量
在 Android 中有两个主要的方法对图片进行解码:ARGB8888 和 RGB565。前者为每个像素使用了 4 个字节,后者每个像素使用了 2 个字节。ARGB8888 的优势是图像质量更高以及能存储一个 alpha 通道。 Picasso使用 ARGB8888,Glide 默认使用低质量的 RGB565。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
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
中将GlideModule
定义为meta-data
1
2
|
<meta-data android:name=
"com.inthecheesefactory.lab.glidepicasso.GlideConfiguration"
android:value=
"GlideModule"
/>
|