将bitmap按照centercrop的方式截取
2016-03-30 16:17
302 查看
将已经加载得到的bitma以一定比例截取图片,newWidth,
newHeight是想要得到图片的大小,可以传入屏幕的宽高
public static Bitmap zoomImg(Bitmap bm, int newWidth, int newHeight) {int w = bm.getWidth(); // 得到图片的宽,高int h = bm.getHeight();int retX;int retY;double wh = (double) w / (double) h;double nwh = (double) newWidth / (double) newHeight;if (wh > nwh) {retX = h * newWidth / newHeight;retY = h;} else {retX = w;retY = w * newHeight / newWidth;}int startX = w > retX ? (w - retX) / 2 : 0;//基于原图,取正方形左上角x坐标int startY = h > retY ? (h - retY) / 2 : 0;Bitmap bit = Bitmap.createBitmap(bm, startX, startY, retX, retY, null, false);bm.recycle();return bit;}
相关文章推荐
- Linux Shell常用技巧(五) awk编程
- Linux Shell常用技巧(四) awk
- Linux——多线程
- Linux学习历程(持续更新整理中)
- (OK) cBPM-CentOS——Criteria.xml——create-database
- opencv删除二值图中较小的噪点色块
- Ununtu14.04下安装Hadoop2.6.0常见问题解决
- Linux和windows、Mac回车换行区别
- DigitalOcean的Droplet怎么添加SSH Key和使用SSH Key登录
- linux 学习之路(学linux必看)
- Linux Shell常用技巧(三) sed
- Linux Shell常用技巧(二) grep
- shell中几种括号的结构和变量替换
- Linux Shell常用技巧(一) RE
- Linux命令vi/vim
- 《LINUX内核分析》第六周作业:Linux系统如何创建一个新进程
- Nginx、LVS、HAProxy负载均衡软件的优缺点
- Linux的计划任务
- Linux 服务器下 Apache 无法解析 PHP 程序
- (OK) centos7 编译 php-5.6.14