当前位置:网站首页>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);
边栏推荐
- MySQL数字类型学习笔记
- A high density 256 channel electrode cap for dry EEG
- View Slide
- Advanced opencv:bgr pixel intensity map
- 面试:Bitmap像素内存分配在堆内存还是在native中
- pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
- 官网给的这个依赖是不是应该为flink-sql-connector-mysql-cdc啊,加了依赖调
- 报错:Module not found: Error: Can‘t resolve ‘XXX‘ in ‘XXXX‘
- How to judge that the thread pool has completed all tasks?
- Theme. AppCompat. Light. Darkactionbar not found
猜你喜欢
《天天数学》连载58:二月二十七日
自动化规范检查软件如何发展而来?
What is the origin of the domain knowledge network that drives the new idea of manufacturing industry upgrading?
uniapp + uniCloud+unipay 实现微信小程序支付功能
Wechat applet - simple diet recommendation (4)
Wechat applet - simple diet recommendation (3)
Cent7 Oracle database installation error
Have you learned to make money in Dingding, enterprise micro and Feishu?
A high density 256 channel electrode cap for dry EEG
AtCoder Beginner Contest 254「E bfs」「F st表维护差分数组gcd」
随机推荐
B站大量虚拟主播被集体强制退款:收入蒸发,还倒欠B站;乔布斯被追授美国总统自由勋章;Grafana 9 发布|极客头条...
leetcode:1200. 最小绝对差
Personal website construction tutorial | local website environment construction | website production tutorial
vscode的快捷键
如何獲取GC(垃圾回收器)的STW(暫停)時間?
The king of pirated Dall · e? 50000 images per day, crowded hugging face server, and openai ordered to change its name
Kotlin Compose 多个条目滚动
[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
Click the picture in the mobile browser and the picture will not pop up
Flutter development: a way to solve the problem of blank space on the top of listview
Wechat applet - simple diet recommendation (3)
mysql80服务不启动
CSDN always jumps to other positions when editing articles_ CSDN sends articles without moving the mouse
How to judge that the thread pool has completed all tasks?
Six simple cases of QT
StaticLayout的使用详解
程序员搞开源,读什么书最合适?
. Net delay queue
Coffeescript Chinese character to pinyin code
Theme. AppCompat. Light. Darkactionbar not found