Android--Bitmap处理、圆角、圆形
/**
* 转换图片成圆形
*
* @param bitmap
* 传入Bitmap对象
* @return
*/
public static Bitmap toRoundBitmap(Bitmap bitmap) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float roundPx;
float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
if (width <= height) {
roundPx = width / 2;
top = 0;
bottom = width;
left = 0;
right = width;
height = width;
dst_left = 0;
dst_top = 0;
dst_right = width;
dst_bottom = width;
} else {
roundPx = height / 2;
float clip = (width - height) / 2;
left = clip;
right = width - clip;
top = 0;
bottom = height;
width = height;
dst_left = 0;
dst_top = 0;
dst_right = height;
dst_bottom = height;
} Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(output); final int color = 0xff424242;
final Paint paint = new Paint();
final Rect src = new Rect((int) left, (int) top, (int) right,
(int) bottom);
final Rect dst = new Rect((int) dst_left, (int) dst_top,
(int) dst_right, (int) dst_bottom);
final RectF rectF = new RectF(dst); paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, src, dst, paint);
return output;
} /**
* to圆角Bitmap
* @param bitmap
* @return
*/
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap,float roundPx) {
try {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;// 颜色值(0xff---alpha)
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);// Rect是使用int类型作为数值,RectF是使用float类型作为数值
// --------抗锯齿-------//
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
final Rect src = new Rect(0, 0, bitmap.getWidth(),
bitmap.getHeight());
canvas.drawBitmap(bitmap, null, rect, paint);
return output;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Android--Bitmap处理、圆角、圆形的更多相关文章
- Android Xfermode 实战 实现圆形、圆角图片
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42094215,本文出自:[张鸿洋的博客] 1.概述 其实这篇本来准备Androi ...
- Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案
Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案 RoundedBitmapDrawable是Android在support v4的扩展包中新 ...
- Android bitmap图片处理
一.View转换为Bitmap 在Android中所有的控件都是View的直接子类或者间接子类,通过它们可以组成丰富的UI界面.在窗口显示的时候Android会把这些控件都加载到内存中 ...
- android ImageView加圆角
1.attrs添加 <declare-styleable name="RoundImageView"> <attr name="circle" ...
- Android View加载圆形图片且同时绘制圆形图片的外部边缘边线及边框:LayerDrawable实现
Android View加载圆形图片且同时绘制圆形图片的外部边缘边线及边框:LayerDrawable实现 LayerDrawable实现的结果和附录文章1,2,3中的layer-list一致. ...
- Android ImageView加载圆形图片且同时绘制圆形图片的外部边缘边线及边框
Android ImageView加载圆形图片且同时绘制圆形图片的外部边缘边线及边框 在Android早期的开发中,如果涉及到圆形图片的处理,往往需要借助于第三方的实现,见附录文章1,2.And ...
- Android自己定义圆角ImageView 支持网络图片
先看下效果图 我们再来看一张CSDN的圆角图片 从布局能够看出csdn app 的头像也是圆角的Image,但能够看到.有明显的毛刺感.不知道是csdn 程序猿的疏忽还是 我手机的问题,本人手机(小米 ...
- Android开发之制作圆形头像自定义View,直接引用工具类,加快开发速度。带有源代码学习
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 QQ986945193 博客园主页:http://www.cnblogs.com/mcxiaobing ...
- [翻译]开发文档:android Bitmap的高效使用
内容概述 本文内容来自开发文档"Traning > Displaying Bitmaps Efficiently",包括大尺寸Bitmap的高效加载,图片的异步加载和数据缓存 ...
- Android Bitmap 和 ByteArray的互相转换
Android Bitmap 和 ByteArray的互相转换 移动平台图像处理,需要将图像传给native处理,如何传递?将bitmap转换成一个 byte[] 方便传递也方便cpp代码直接处理图像 ...
随机推荐
- rust学习
Rust (github) 1. install (https://rustup.rs/) 2. play on line curl https://sh.rustup.rs -sSf | sh e ...
- GitHub页面基本知识
官网地址:https://help.github.com/categories/github-pages-basics/ GitHub页面是什么? GitHub页面是一个静态的站点托管服务. GitH ...
- GoCN每日新闻(2019-10-06)
GoCN每日新闻(2019-10-06) 国庆专辑:GopherChina祝大家国庆节快乐 GoCN每日新闻(2019-10-06) 1. Go 1.14 有什么新变化 http://docs.goo ...
- vue中父级与子组件生命周期的先后顺序
1.vue的生命周期 2.views/createrCustormer.vue为父级 <template> <expressService /> </ ...
- 事务控制语言(TCL)
一个或一组sql语句组成一个执行单元,这个执行单元要么全部执行,要么全部不执行.如:转账. 原子性(Atomicity):一个事务要么都执行,要么都回滚(不可再分割) 一致性(Consistency) ...
- 利用python做矩阵的简单运算(行列式、特征值、特征向量等的求解)
import numpy as np lis = np.mat([[1,2,3],[3,4,5],[4,5,6]]) print(np.linalg.inv(lis)) # 求矩阵的逆矩阵 [[-1. ...
- MongoDB 高级查询_aggregate聚合管道
MongoDB 聚合管道(AggregationPipeline) 使用聚合管道可以对集合中的文档进行变换和组合.实际项目应用主要是表关联查询.数据的统计. MongoDB 中使用 db.COLLEC ...
- span 不使用float 靠右对齐且垂直居中
一般让div 里的span 靠右对齐用的方法比较多的是float:right. 这次由于各种原因我不想用float 先看效果: HTML 部分 <div class="customer ...
- js十大排序算法收藏
十大经典算法排序总结对比 转载自五分钟学算法&https://www.cnblogs.com/AlbertP/p/10847627.html 一张图概括: 主流排序算法概览 名词解释: n: ...
- 工具系列 | VScode Remote 远程开发与调试(告别SSH)
简介 最近VScode发布了远程编程与调试的插件Remote Development,使用这个插件可以在很多情况下代替vim直接远程修改与调试服务器上的代码,同时具备代码高亮与补全功能,就和在本地使用 ...