当前位置:网站首页>Getting started with glide4
Getting started with glide4
2022-08-08 17:18:00 【Wholehearted】
Directory:
I. Introduction
Same as other image loading libraries, Glide can load local images in addition to network images.You can even load images from all sorts of weird data sources.This article will introduce how to use Glide4 to load network pictures, local pictures, and pictures in resource files.
Second, load network pictures
This has been mentioned before, just put a piece of code, so I won't explain much.
1
2
3
4
5
ImageView imageView = findViewById(R.id.image_view);
String url = “https://www.niwoxuexi.com/statics/images/nougat_bg.png”;
Glide.with(context)
.load(url)
.into(imageView);
3. Load local image
glide is also very simple to record local images, and it is also implemented through .load() . Let's take a look at .load() to load various resources
Note: The permission to read the SD card should be added to the AndroidManifest.xml for loading the SD card image
1
如果是运行在Android 6.0 以上的手机上,还要在代码中动态的申请读取SD卡的权限(我这里就不多讲了,大家可以自行从网上查找)
1, load the SD card resource image
1
2
3
4
5
// Load the test.jpg image in the root directory of the SD card
String path = “file://” + Environment.getExternalStorageDirectory().getPath()+“/test.jpg”;
Glide.with(context)
.load(path)
.into(imageView);
or
1
2
3
4
5
6
ImageView imageView = findViewById(R.id.image_view);
// Load the root directory of SD cardtest.jpg image, read through Flie file
File file = new File(Environment.getExternalStorageDirectory(), “test.jpg”);
Glide.with(context)
.load(file)
.into(imageView);
2, load the drawable resource image
Method: load(R.drawable.image_test)
1
2
3
4
5
ImageView imageView = findViewById(R.id.image_view);
// Load the image image_test.png under the resource file drawable
Glide.with(this)
.load(R.drawable.iamge_test)
.into(imageView);
3. Load assets resource file
Method: load("file:///android_asset/image_test.png")
1
2
3
4
5
6
ImageView imageView = findViewById(R.id.image_view);
// Load the resource file under assetsImage image_test.png
String path = “file:///android_asset/image_test.png”;
Glide.with(this)
.load(path)
.into(imageView);
4. Load raw resource image
Method: load("android.resource://package name/raw/raw_1") or load("android.resource://package name/raw/"+R.raw.raw_1)
I'm not going to code this, let's draw a scoop of rice gourd
5, of course, load is not limited to the above types, and the following parameters can also be loaded. I will not give an example. Anyone who is interested can learn from Baidu by themselves
Parameter description
.load(String string) string can be a file path, uri or url
.load(Uri uri) uri type
.load(File file) file
.load(Integer resourceId) Resource Id, R.drawable.xxx or R.mipmap.xxx
.load(byte[] model) byte[] type
.load(T model) custom type
3.The next article is to learn glide to load gif images
边栏推荐
猜你喜欢
随机推荐
多线程-并发编程
【数学模型】TOPSIS
Obtain - 64 [chances] : the soldier, subtlety also - 5 - read sun tzu - melee meter
Tensorflow教程(二)——基本概念与搭建流程
laravel-实践
企业“数字化转型”成功的2个必备条件!
The latest research from PNAS: 81% problem solving rate, neural network Codex opens the door to the world of advanced mathematics
PNAS最新研究:81%解题率,神经网络 Codex 推开高等数学世界大门
顺序表与链表结构及解析
dp,dpi,px知识补充
文件操作和IO
二、junit接口自动化框架之二次开发
【开源教程2】疯壳·开源编队无人机-硬件资源简介
leetcode:295. 数据流的中位数
L2-012 关于堆的判断 (25 分)(堆)
[Paper Reading] RAL 2022: Receding Moving Object Segmentation in 3D LiDAR Data Using Sparse 4D Convolutions
D. Districts Connection
Tensorflow教程(四)——MNIST项目入门
【LeetCode】Exam Summary: Depth-First Search (DFS)
Charles MOCK 数据 htpps代理