0

I am currently using the following snippet of code to set my wallpaper background. My problem is that the full image doesn't appear on the wallpaper. It is always clipped and missing objects from the bottom and side views of the wallpaper. I've tried to crop the photo, to resize the image, and I also tried to change the resolution to match that of my emulator. None of this works. Do any of you know how to display the full image using the code below:

Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.testimg2);
try {
      wpm.setBitmap(background);
}catch(...){
....
}

Updated code (that still crops the image):

int width = display.getWidth();
 int height = display.getHeight();
 Log.v("WALLPAPER", "width and height are " + width + " " + height);
 Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.testimg2);
 Bitmap scaled = Bitmap.createScaledBitmap(background, width, height, true);
user836200
  • 655
  • 2
  • 12
  • 20
  • [Post is old but anyway... You can try something similar to this](http://stackoverflow.com/a/41347058/1685165) – Dark Dec 28 '16 at 13:14

1 Answers1

2

The problem is probably the resolution the wallpaper manager desires. It's probably double the width of the screen, and it resizes the wallpaper so it fits the desired parametres. Try this to find out what the desired wallpaper resolution is, using

int minH, minW;
WallpaperManager myWallpaperManager  = WallpaperManager.getInstance(getApplicationContext());
minH = myWallpaperManager.getDesiredMinimumHeight();
minW = myWallpaperManager.getDesiredMinimumWidth();
Log.d("TAG", "The desired wallpaper height is: " + minH + "; and the desired width is:" + minW);

After that make a Bitmap.createScaledBitmap with minH and minW. And remember to put this when you create the bitmap:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
SeanC
  • 15,695
  • 5
  • 45
  • 66