Android调整Bitmap图片大小

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013293125/article/details/81158208

Android调整Bitmap图片大小

/**
     * 调整图片大小
     * 
     * @param bitmap
     *            源
     * @param dst_w
     *            输出宽度
     * @param dst_h
     *            输出高度
     * @return
     */
    public static Bitmap imageScale(Bitmap bitmap, int dst_w, int dst_h) {
        int src_w = bitmap.getWidth();
        int src_h = bitmap.getHeight();
        float scale_w = ((float) dst_w) / src_w;
        float scale_h = ((float) dst_h) / src_h;
        Matrix matrix = new Matrix();
        matrix.postScale(scale_w, scale_h);
        Bitmap dstbmp = Bitmap.createBitmap(bitmap, 0, 0, src_w, src_h, matrix,
                true);
        return dstbmp;
    }

猜你喜欢

转载自blog.csdn.net/u013293125/article/details/81158208
今日推荐