BitmapUtils.java 文件源码

java
阅读 47 收藏 0 点赞 0 评论 0

项目:Mvp-Retrofit-Rxjava-Rxbus 作者:
public static Bitmap getScaleBitmap(Context context, String imagePath,
        int maxWidth) {
    try {
        Options bitmapOptions = new Options();
        bitmapOptions.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(imagePath, bitmapOptions);
        int imageWidth = bitmapOptions.outWidth;

        if (maxWidth == 0) {
            maxWidth = DevUtils.getScreenWidth(context);
        } else if (maxWidth < 0) {
            maxWidth = imageWidth;
        }

        if (imageWidth < maxWidth) {
            maxWidth = imageWidth;
        }

        Bitmap bitmap = createScaleBitmapByWidthIfNeed(imagePath, maxWidth);
        return bitmap;
    } catch (OutOfMemoryError e) {
        Log.e("BitmapUtils", "compressBitmap", e);
        return null;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号