S
S
Stanislav2017-05-15 19:30:30
Java
Stanislav, 2017-05-15 19:30:30

Why does android stretch image on (SET_WALLPAPER)?

I don’t understand why there is another resize of the picture when setting it as wallpaper.
I find out the resolution of the display and crop the image to fit it

public void setWallpaper(Bitmap bitmap, List<Integer> size) {

        Log.d(TAG, "width display: " + size.get(0)); // 1280
        Log.d(TAG, "height display: " + size.get(1)); // 720
        Log.d(TAG, "width bitmap: " + bitmap.getWidth()); // 1480
        Log.d(TAG, "height bitmap: " + bitmap.getHeight()); // 720

        Bitmap dstBmp;

        if (bitmap.getWidth() >= bitmap.getHeight()){

            dstBmp = Bitmap.createBitmap(
                    bitmap,
                    bitmap.getWidth()/2 - size.get(0)/2, // x = 100
                    0, // y = 0
                    size.get(0), // width = 1280
                    size.get(1) // height = 720
            );

        } else {

            dstBmp = Bitmap.createBitmap(
                    bitmap,
                    0,
                    size.get(1)/2 - bitmap.getWidth()/2,
                    size.get(0),
                    size.get(1)
            );
        }

        WallpaperManager wm = WallpaperManager.getInstance(getApplicationContext());

        try {
            wm.setBitmap(dstBmp);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

The picture is stretched and the image quality is terribly lost, maybe I'm not calculating the display resolution correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question