ImageUtils.java 文件源码

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

项目:Resizer 作者:
public static Bitmap getScaledBitmap(int targetLength, File sourceImage) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = false;
    Bitmap bitmap = BitmapFactory.decodeFile(sourceImage.getAbsolutePath(), options);

    // Get the dimensions of the original bitmap
    int originalWidth = options.outWidth;
    int originalHeight = options.outHeight;
    float aspectRatio = (float) originalWidth / originalHeight;

    // Calculate the target dimensions
    int targetWidth, targetHeight;

    if (originalWidth > originalHeight) {
        targetWidth = targetLength;
        targetHeight = Math.round(targetWidth / aspectRatio);
    } else {
        aspectRatio = 1 / aspectRatio;
        targetHeight = targetLength;
        targetWidth = Math.round(targetHeight / aspectRatio);
    }

    return Bitmap.createScaledBitmap(bitmap, targetWidth, targetHeight, true);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号