glide 长方形图片显示圆角问题
目前业务是RecyclerView嵌套RecyclerView,子RecyclerView里面显示图片,图片显示方式又分为 多图和单图显示方式(这个是已经调试好的效果)

测试显示结果只有单张图片不显示圆角,直觉告诉我可能是图片太大了(260*100)那就改小点 比如200*160 测试显示还是一样的效果,没有任何反应。
索性直接把单个图片的大小改成和多图一样的,运行测试我去奇迹出现了 居然有圆角了 有圆角了 这是什么情况 难道是图片只能是正文形?想着glide不能这么变态吧(哈哈)
又在想网找了几个圆角的公共类 发现没啥不一样,在找到 https://github.com/wildma/GlideRoundImage/blob/master/GlideRoundImage.java 看到写前4.0以上代码问题
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight);
return roundCrop(pool, bitmap);
}
完整代码
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils; import java.security.MessageDigest; public class GlideRoundTransform extends BitmapTransformation { private static float radius = 0f; public GlideRoundTransform(Context context) {
this(context, 3);
} public GlideRoundTransform(Context context, int dp) {
this.radius = Resources.getSystem().getDisplayMetrics().density * dp;
} @Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight);
return roundCrop(pool, bitmap);
} private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
if (result == null) {
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
} Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);
RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
canvas.drawRoundRect(rectF, radius, radius, paint);
return result;
} @Override
public void updateDiskCacheKey(MessageDigest messageDigest) { }
}
glide 长方形图片显示圆角问题的更多相关文章
- Android 图片设置圆角
Android中经常会遇到对图片进行二次处理,例如加圆角,或者显示圆形图片 方法一: 通过第三方框架Glide实现图片显示有圆角,有三种写法如下: 1.1,第一种实现: RequestOptions ...
- Glide 加载部分圆角图片
在App开放中经常遇到设置ImageView为部分圆角的情况,但是Glide又没有提供这个方法,该怎么办呢?直接上代码! /** * @author csc * @date 2019-01-18 ...
- Glide.centerCrop()第一次显示无效
Glide.with(context) .load(url) .centerCrop() /** fitCenter() */ .placeholder(R.mi ...
- swift UIImage加载远程图片和圆角矩形
UIImage这个对象是swift中的图像类,可以使用UIImageView加载显示到View上. 以下是UIImage的构造函数: init(named name: String!) -> U ...
- 4.C#WinForm基础图片(显示和隐藏)
要求: 软件上有一张图片,默认是隐藏的.用户在文本框中输入身份证号(131226198105223452),点击按钮,如果年龄大于18岁,则显示图片. 知识点: 取当前年份,Date Time Now ...
- jQuery css3鼠标悬停图片显示遮罩层动画特效
jQuery css3鼠标悬停图片显示遮罩层动画特效 效果体验:http://hovertree.com/texiao/jquery/39/ 效果图: 源码下载:http://hovertree.co ...
- Glide请求图片能携带Cookie的哟!
在Web编程中我们都很熟知一个概念,当有了seesion登录状态时,你可以访问一些资源但如果你没有登录的话很多资源是无法访问的. 在android的WebApi中当然一样拥有这个概念.比如,用户的头像 ...
- Latex图片显示问题(1)
用latex编译后,若用dvipdf生成pdf文件,则其中有个eps图的左侧会显示不完全:若是用dvips--pspdf生成pdf文件,图像显示没问题. 这种情况的问题出在,加载 graphicx 宏 ...
- WPF 图片显示中的保留字符问题
在WPF中显示一张图片,本是一件再简单不过的事情.一张图片,一行XAML代码即可. 但是前段时间遇到了一件奇怪的事: 开发机上运行正常的程序,在某些客户机器上却显示不了图片,而且除了这个问题,其它运行 ...
随机推荐
- Matlab_spectrogram_短时傅里叶分析_实现与讨论
在语音与音乐处理过程中,常用到短时傅里叶变换(Short Time Fourier Transformation, STFT).在一些学习路径中,STFT也是学习小波之前的预备知识.本文简单实现了 M ...
- mac pkg移除
1打开终端 sudo bash < <(curl -sL https://raw.github.com/mpapis/pkg_uninstaller/master/pkg-install) ...
- sparksql错误报No such file or director
今天在非hadoop用户使用sparksql处理insert overwrite table a select b left join c这个句型遇到以下的错误. Error: org.apache. ...
- a链接中 JS弹出确认对话框方法
一种: <a href="javascript:if(confirm('确实要删除该内容吗?'))location='http://www.google.com'">弹 ...
- 移除元素-leetcode-27
class Solution {public: int removeElement(vector<int>& nums, int val) { if(nums. ...
- Python基础:八、python基本数据类型
一.什么是数据类型? 我们人类可以很容易的分清数字与字符的区别,但是计算机并不能,计算机虽然很强大,但从某种角度上来看又很傻,除非你明确告诉它,"1"是数字,"壹&quo ...
- nginx配置静态页面访问
server { server_name static.naice.me; // 你的域名或者 ip # 域名:static.naice.me 这里用 "_" 代表获取匹配所有 ...
- [SQL] 从文本中提取数值
现需求从上方测试数据的“备注”列中提取出金额 目前有两个方法比较容易实现: 1.首先比较容易想到的就是利用函数stuff删除掉所有的非数值字符. STUFF ( character_expressio ...
- Demystify Git
Git虽然很时髦,但是不好学,不好用. 关键是不好理解. 本文用最通俗易懂又直观的方式,帮助大家理解git, git的内部组织, 基本概念,还有常用 的工作流程. 本文来自墙外. 习某某说:" ...
- 迁移32位下的旧代码到64位sever遇到过的两个很诡异的问题
一个是GetHashCode,这个方法是返回一个int值,在32位系统里,都是正值,但在64位系统里会返回负值. 另一个问题是DataTable的Sort属性,在没有显示写明升序或降序的情况下,在32 ...