4

I am using a simplest code to set wallpaper:

Bitmap bmap2 = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.a));

getApplicationContext().setWallpaper(bmap2);

And the problem occur when image size is bigger than screen size. I can see only the part of input picture.

I tried resizing methods like createScaledBitmap and it works, but not like I want. createScaledBitmap is resizing bitmap, but not size of picture, just resolution (just mess up the quality of picture, not picture size loaded to phone as wallpaper).

Does anyone know how to scale down the size of image, not a resolution?

EDIT:

Few screens:

Images from menu, before scale and after scale:

http://zapodaj.net/14097596e4251.png.html

So as you can see there is only scaled resolution, not size of picture.

Any ideas??

Tomi89
  • 41
  • 1
  • 1
  • 3
  • 1
    As a note, `setWallpaper` is deprecated since API level 5. You might want to look into [WallpaperManager](http://developer.android.com/reference/android/app/WallpaperManager.html) which has many utilities. – adrianp May 03 '13 at 12:22
  • I also tried: WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); wallpaperManager.setBitmap(bmap2); but it's the same. (at least result) – Tomi89 May 03 '13 at 12:52
  • 1
    Already solved problem. That code helped me: DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; Bitmap bitmap = Bitmap .createScaledBitmap(whatever, width, height, true); – Tomi89 May 04 '13 at 22:34

1 Answers1

16

Answer from the author is in the comments, but as nobody see comments, I copy it here:

Bitmap bmap2 = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.paper));

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels; 
int width = metrics.widthPixels;
Bitmap bitmap = Bitmap.createScaledBitmap(bmap2, width, height, true); 

WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this); 
 try {
  wallpaperManager.setBitmap(bitmap);
 } catch (IOException e) {
  e.printStackTrace();
 }
Reza_Rg
  • 3,345
  • 7
  • 32
  • 48