您的位置:首页 > 运维架构

将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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: