调整墙纸大小以适合屏幕大小而不裁切或缩放吗?

时间:2018-08-05 18:39:12

标签: android image android-studio wallpaper

我正在从应用程序中设置图像作为墙纸,它在诺基亚5上运行良好,并且正在设置图像并填充整个视图,但是当我尝试在huawei Honor 5x或nexus 4上运行相同的代码时图像被放大并离开主屏幕。

private Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
        
        int width = bm.getWidth();
        int height = bm.getHeight();
       
       
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;
        // create a matrix for the manipulation
        Matrix matrix = new Matrix();
        // resize the bit map
        matrix.postScale(scaleWidth, scaleHeight);

        // recreate the new Bitmap
        Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);

        return resizedBitmap;
    }

0 个答案:

没有答案