public static Bitmap scaleImage(Bitmap bitmap, int boxSize){
if (boxSize == 0)
return null;
// Determine how much to scale: the dimension requiring less scaling is
// closer to the its side. This way the image always stays inside your
// bounding box AND either x/y axis touches it.
float xScale = ((float) boxSize) / bitmap.getWidth();
float yScale = ((float) boxSize) / bitmap.getHeight();
float scale = (xScale <= yScale) ? xScale : yScale;
// Create a matrix for the scaling and add the scaling data
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
// Create a new bitmap and convert it to a format understood by the ImageView
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
}
ImageUtils.java 文件源码
java
阅读 40
收藏 0
点赞 0
评论 0
项目:chat-sdk-android-push-firebase
作者:
评论列表
文章目录