android裁剪缩略图的方法
public static Bitmap corp(Bitmap bitmap) {int corpWith = Configs.CORP_THUMBS_WIDTH;int corpHeight = Configs.CORP_THUMBS_HEIGHT;int width = bitmap.getWidth(); int height = bitmap.getHeight(); int srcLeft = 0; int srcTop = 0; int dstLeft = 0; int dstTop = 0; Bitmap output = Bitmap.createBitmap(corpWith,corpHeight, Config.ARGB_8888);Canvas canvas = new Canvas(output);if(corpWith >= width){dstLeft = (corpWith -width)/2;corpWith = width;}else{srcLeft = (width - corpWith)/2;} if(corpHeight >= height){ dstTop = (corpHeight - height)/2; corpHeight = height; }else{ srcTop = (height - corpHeight)/2; } Log.i(Constants.LOG_TAG_DEBUG, "corpWith:" + corpWith + ",corpHeight:" + corpHeight + ",dstLeft:" + dstLeft + ",dstTop:"+dstTop);final int color = 0xff424242;final Paint paint = new Paint();final Rect dstRect = new Rect(dstLeft, dstTop, corpWith + dstLeft, corpHeight + dstTop);final Rect srcRect = new Rect(srcLeft, srcTop, corpWith + srcLeft, corpHeight + srcTop);final RectF rectF = new RectF(dstRect);final float roundPx = Configs.CORP_THUMBS_ROUND; //圆角像素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, srcRect, dstRect, paint);return output;}Rect dstRect = new Rect(dstLeft, dstTop, corpWith + dstLeft, corpHeight + dstTop);