0

I have a little problem with scaling down images. On big resolution phones all images are looking ok, but when it needs to scale down image on smaller phones, images are looking not smooth. Maybe someone can help me, how to improve image quality after down scaling. Thanks in advance. Here is some screen shoots from Note 4 and S2 phones:

Note 4 Screen Shoot, upscale from 3840x2160 to 4551x2560

S2 Screen Shoot, downscale from 3840x2160 to 1422x800

    Bitmap bitmap;

public void setWallpaper() {

    Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.raw.img_test));

    float screenWidth, screenHeight;
    float bitmap_width = bitmap.getWidth(), bitmap_height = bitmap.getHeight();

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    screenWidth = display.getWidth();
    screenHeight = display.getHeight();

    float bitmap_ratio = bitmap_width / bitmap_height;
    float screen_ratio = screenWidth / screenHeight;
    int bitmapNewWidth, bitmapNewHeight;

    if (screen_ratio > bitmap_ratio) {
        bitmapNewWidth = (int) screenWidth;
        bitmapNewHeight = (int) (bitmapNewWidth / bitmap_ratio);
    } else {
        bitmapNewHeight = (int) screenHeight;
        bitmapNewWidth = (int) (bitmapNewHeight * bitmap_ratio);
    }

    bitmap = Bitmap.createScaledBitmap(bitmap, bitmapNewWidth, bitmapNewHeight, true);

    try {
        WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
        myWallpaperManager.setBitmap(bitmap);
        Toast.makeText(getApplicationContext(), "Set wallpaper successfully!", Toast.LENGTH_SHORT).show();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

1 Answers1

0

Use the following to scale your images

Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);
Pinks
  • 958
  • 7
  • 10