当前位置:网站首页>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);
边栏推荐
- Mysql80 service does not start
- To bring Euler's innovation to the world, SUSE should be the guide
- 自动化规范检查软件如何发展而来?
- Pagoda panel MySQL cannot be started
- 学习笔记6--卫星定位技术(上)
- How to write high-quality code?
- The comparison of every() and some() in JS uses a power storage plan
- 最全是一次I2C总结
- Tianlong Babu TLBB series - about items dropped from packages
- 【JS】数组降维
猜你喜欢
Six simple cases of QT
To bring Euler's innovation to the world, SUSE should be the guide
Generics, generic defects and application scenarios that 90% of people don't understand
> Could not create task ‘:app:MyTest.main()‘. > SourceSet with name ‘main‘ not found.问题修复
[C language] the use of dynamic memory development "malloc"
Design and Simulation of fuzzy PID control system for liquid level of double tank (matlab/simulink)
How to write high-quality code?
.Net之延迟队列
Mysql80 service does not start
The most complete is an I2C summary
随机推荐
Coffeescript Chinese character to pinyin code
官网给的这个依赖是不是应该为flink-sql-connector-mysql-cdc啊,加了依赖调
《天天数学》连载58:二月二十七日
Cerebral Cortex:有向脑连接识别帕金森病中广泛存在的功能网络异常
Applet image height adaptation and setting text line height
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
CSDN always jumps to other positions when editing articles_ CSDN sends articles without moving the mouse
Kotlin compose and native nesting
Design of stepping motor controller based on single chip microcomputer (forward rotation and reverse rotation indicator gear)
一种用于干式脑电图的高密度256通道电极帽
@JsonAdapter注解使用
把欧拉的创新带向世界 SUSE 要做那个引路人
程序员如何活成自己喜欢的模样?
Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 -下
如何写出高质量的代码?
微信小程序中,从一个页面跳转到另一个页面后,在返回后发现页面同步滚动了
ConstraintLayout的流式布局Flow
ArcGIS Pro 创建要素
Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 - 上