Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - set wallpaper to fit phone screen size

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??

like image 857
Tomi89 Avatar asked Dec 04 '22 11:12

Tomi89


1 Answers

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();
 }
like image 136
Reza_Rg Avatar answered Feb 03 '23 08:02

Reza_Rg