当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
1dp到底多大!
LeetCode_Backtrack_Medium_491. Incrementing Subsequence
一、根据系统架构定位系统性能瓶颈
同态加密:正则嵌入、理想格和RLWE问题
leetcode:294.翻转游戏
【LeetCode】Exam Summary: Depth-First Search (DFS)
[Paper Reading] RAL 2022: Receding Moving Object Segmentation in 3D LiDAR Data Using Sparse 4D Convolutions
二、pytest+selenium+allure实现web ui自动化
李沐:机器学习者进阶学习建议
第二十章 源代码文件 REST API 参考(二)
软件工程基础知识--认识软件工程
C#异步和多线程
敏捷开发项目管理的一些心得
H. Huge Boxes of Animal Toys
4. S32K14X study notes: S32 Design Studio new and imported projects
L2-016 愿天下有情人都是失散多年的兄妹 (25 分)
arm交叉编译
leetcode:306. 累加数
redis介绍&命令&性能相关&缓存穿透
离线安装 Anaconda + TensorFlow