0

It seems that setting a wallpaper on Android just doesn't work in any useful way.

  • If you get an image from your phone and set it as the wallpaper, it's way too big for the screen
  • If you resize it (either using a createBitmap() function that allows you to specify size, or the ridiculously useless createScaledBitmap()) it goes all jaggy and out of focus
  • If you use some freaky hacks to fix the quality of the image, it's better, but still not perfectly clear by any stretch.
  • If you attempt to get the current wallpaper and set that, it still seems to make it too big. It appears to give you the original image file, forcing you to resize it, which doesn't work.

Now, the phone's internal software is perfectly capable of resizing an image to be smaller with no reduction of quality. Why does it not share this functionality?

WallpaperManager wallpaperManager = WallpaperManager.getInstance(Spinnerz.this);

// gets the image from file, inexplicably upside down.
Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "DCIM/Camera/Zedz.jpg");

// use some rotation to get it on an angle that matches the screen.
Matrix bitmapTransforms = new Matrix();
bitmapTransforms.setRotate(90); // flip back upright
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),bitmapTransforms, false); // create bitmap from bitmap from file, using the rotate matrix

// lets set it exactly to the resolution of my Samsung Galaxy S2: 480x800 pixels.
// This function appears to exist specifically to scale a bitmap object - should do a good job of it!
bitmap = Bitmap.createScaledBitmap(bitmap, 480, 800, false);
wallpaperManager.setBitmap(bitmap);

// result is quite a jaggy image - not suitable as a wallpaper.

PIC:

Mohsen Safari
  • 6,669
  • 5
  • 42
  • 58
Nauraushaun
  • 1,484
  • 12
  • 10

1 Answers1

0

Try this ,

  Display d = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
                        int width = d.getWidth();
                        int height = d.getHeight();
Numair
  • 1,062
  • 1
  • 20
  • 41
  • The problem isn't getting the dimensions of the screen. The problem is that if I set the image to those dimensions, it resizes to a horrible quality. – Nauraushaun Aug 25 '12 at 05:06
  • Added some code. Managed to clean it up mostly, but it's still not useful. – Nauraushaun Aug 30 '12 at 10:35