当前位置:网站首页>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);
边栏推荐
- 高级 OpenCV:BGR 像素强度图
- Tianlong Babu TLBB series - about items dropped from packages
- Wechat applet - simple diet recommendation (3)
- 【JS】数组降维
- 最全是一次I2C总结
- mysql80服务不启动
- Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
- Design and Simulation of fuzzy PID control system for liquid level of double tank (matlab/simulink)
- Kotlin compose and native nesting
- Kotlin Compose 多个条目滚动
猜你喜欢
[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution
【小技巧】獲取matlab中cdfplot函數的x軸,y軸的數值
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package can be used directly - next
MySQL字符类型学习笔记
AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
双容水箱液位模糊PID控制系统设计与仿真(Matlab/Simulink)
Swift set pickerview to white on black background
如何获取GC(垃圾回收器)的STW(暂停)时间?
【 conseils 】 obtenir les valeurs des axes X et y de la fonction cdfplot dans MATLAB
[C language] the use of dynamic memory development "malloc"
随机推荐
IDEA新建sprintboot项目
[200 opencv routines] 219 Add digital watermark (blind watermark)
钉钉、企微、飞书学会赚钱了吗?
StaticLayout的使用详解
ByteDance Interviewer: how to calculate the memory size occupied by a picture
Swift uses userdefaults and codable to save an array of class objects or structure instances
Those who are good at using soldiers, hide in the invisible, and explain the best promotional value works in depth in 90 minutes
《微信小程序-基础篇》小程序中的事件与冒泡
Apache dolphin scheduler system architecture design
Interview: how does the list duplicate according to the attributes of the object?
苹果 5G 芯片研发失败?想要摆脱高通为时过早
The horizontally scrolling recycleview displays five and a half on one screen, lower than the average distribution of five
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
Design and Simulation of fuzzy PID control system for liquid level of double tank (matlab/simulink)
橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布
Have you learned to make money in Dingding, enterprise micro and Feishu?
Personal website construction tutorial | local website environment construction | website production tutorial
C function returns multiple value methods
QT event filter simple case
Matrix processing practice