第一种方式用Gilde,
布局如下:
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/img_content"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.core.widget.NestedScrollView>
使用Glide的时候,需要设置ImageViewTarget,才能获取到高清点图片
AppCompatImageView imageView = this.findViewById(R.id.img_content);
RequestOptions requestOptions =new RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE);
// .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)//关键代码,加载原始大小
// .format(DecodeFormat.PREFER_RGB_565);//设置为这种格式去掉透明度通道,可以减少内存占有
// .placeholder(R.drawable.img_error)
// .error(R.drawable.img_error)
Glide.with(this)
.setDefaultRequestOptions(requestOptions)
.load(url)
.into(new ImageViewTarget<Drawable>(imageView) {
@Override
protected void setResource(@Nullable Drawable resource) {
view.setImageDrawable(resource);
}
});
第二种方式使用BitmapRegionDecoder,参考如下文章:
https://blog.csdn.net/qq_21154101/article/details/105170954
https://developer.android.com/topic/performance/graphics/load-bitmap?hl=zh-cn
网友评论