当前位置:网站首页>Glide Mastery
Glide Mastery
2022-07-05 10:16:00 【asahi_ xin】
Exception logging
RequestListener<String, GlideDrawable> requestListener = new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
Log.v("==========",model);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
};
Glide.with(this)
.load("'=====")
.listener(requestListener)
.error(R.drawable.b)
.into(imageView);
requestListener The parameter type of should be the same as load Consistency of methods .
Picture transformation
When loading pictures , We can also process pictures , Such as rounding , Circularity , Black and white , Fuzziness, etc .
- transform(bitmapTransform) This method can process pictures .
Take rounding as an example
public class CircleCrop extends BitmapTransformation {
public CircleCrop(Context context) {
super(context);
}
@Override
public String getId() {
return "test.nxx.myapplication";
}
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
int diameter = Math.min(toTransform.getWidth(), toTransform.getHeight());
final Bitmap toReuse = pool.get(outWidth, outHeight, Bitmap.Config.ARGB_8888);
final Bitmap result;
if (toReuse != null) {
result = toReuse;
} else {
result = Bitmap.createBitmap(diameter, diameter, Bitmap.Config.ARGB_8888);
}
int dx = (toTransform.getWidth() - diameter) / 2;
int dy = (toTransform.getHeight() - diameter) / 2;
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
BitmapShader shader = new BitmapShader(toTransform, BitmapShader.TileMode.CLAMP,
BitmapShader.TileMode.CLAMP);
if (dx != 0 || dy != 0) {
Matrix matrix = new Matrix();
matrix.setTranslate(-dx, -dy);
shader.setLocalMatrix(matrix);
}
paint.setShader(shader);
paint.setAntiAlias(true);
float radius = diameter / 2f;
canvas.drawCircle(radius, radius, radius, paint);
if (toReuse != null && !pool.put(toReuse)) {
toReuse.recycle();
}
return result;
}
}
getId() Method is required to return a unique string as id, To distinguish from other image transformations . Usually , We can simply return the full class name of the current class .
Glide.with(context).load(url)
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.dontTransform()
.transform(new CircleCrop(context))
.into(imageView);
Image processing is more general , Here we can use third-party libraries to achieve more effects .
quote
implementation 'jp.wasabeef:glide-transformations:2.0.2'
Fuzzify
Glide.with(context).load(url)
.bitmapTransform(new BlurTransformation(context))
.into(imageView);
Black and white
Glide.with(context).load(url)
.bitmapTransform(new GrayscaleTransformation(context))
.into(imageView);
It can also be done at the same time
Glide.with(context).load(url)
.bitmapTransform(new BlurTransformation(context), new GrayscaleTransformation(context))
.into(imageView);
边栏推荐
- 如何獲取GC(垃圾回收器)的STW(暫停)時間?
- Usage differences between isempty and isblank
- Jupiter notebook shortcut key
- View Slide
- . Net delay queue
- Node red series (29): use slider and chart nodes to realize double broken line time series diagram
- 小程序中自定义行内左滑按钮,类似于qq和wx消息界面那种
- leetcode:1200. 最小绝对差
- 伪类元素--before和after
- 如何获取GC(垃圾回收器)的STW(暂停)时间?
猜你喜欢
Single chip microcomputer principle and Interface Technology (esp8266/esp32) machine human draft
程序员搞开源,读什么书最合适?
把欧拉的创新带向世界 SUSE 要做那个引路人
AtCoder Beginner Contest 258「ABCDEFG」
双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)
How to get the STW (pause) time of GC (garbage collector)?
ConstraintLayout的流式布局Flow
能源势动:电力行业的碳中和该如何实现?
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
How to write high-quality code?
随机推荐
钉钉、企微、飞书学会赚钱了吗?
驱动制造业产业升级新思路的领域知识网络,什么来头?
《微信小程序-基础篇》小程序中的事件与冒泡
一个程序员的职业生涯到底该怎么规划?
NCP1342芯片替代料PN8213 65W氮化镓充电器方案
Kotlin Compose 多个条目滚动
面试:List 如何根据对象的属性去重?
Wechat applet - simple diet recommendation (2)
Windows uses commands to run kotlin
Matrix processing practice
IDEA新建sprintboot项目
【 conseils 】 obtenir les valeurs des axes X et y de la fonction cdfplot dans MATLAB
mongoDB副本集
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo
小程序中自定义行内左滑按钮,类似于qq和wx消息界面那种
字节跳动面试官:一张图片占据的内存大小是如何计算
Getting started with Apache dolphin scheduler (one article is enough)
(1) Complete the new construction of station in Niagara vykon N4 supervisor 4.8 software
宝塔面板MySQL无法启动
oracle和mysql批量Merge对比