0

I am trying to set my image as wallpaper but it gets zoomed/cropped when set as wallpaper. I have tried almost everything but nothing works. Here is my piece of code:

public void setAswallpaper(Bitmap wallpaper)
{
    WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;
    System.out.println("screen dimensions "+width+" "+height);
    System.out.println("wallpaper dimensions "+wallpaper.getWidth()+" "+wallpaper.getHeight());
    wallpaper = Bitmap.createScaledBitmap(wallpaper, width*2 , height, true);

    try {
        WallpaperManager wallpaperManager=WallpaperManager.getInstance(context);
        wallpaperManager.suggestDesiredDimensions(width,height);
        System.out.println("wallpaper manager dimensions "+wallpaperManager.getDesiredMinimumWidth()+" "+wallpaperManager.getDesiredMinimumHeight());                         
        wallpaperManager.setBitmap(wallpaper); }
    }
    catch (IOException e)
    {
        e.printStackTrace();
        Toast.makeText(context,
                "Wallpaper Not Set",
                Toast.LENGTH_SHORT).show();}
}

I need help so that I can set my complete image as wallpaper

My image size is : 640*960 bitmap size is : 1960*2880 screen dimensions : 1080*1960

  • Take a look at this: http://developer.android.com/reference/android/app/WallpaperManager.html#suggestDesiredDimensions(int,%20int), also, why width*2 on createScaledBitmap? – Nanoc Sep 17 '15 at 11:35
  • because I read that the width of the bitmap should be twice than screen dimensions so that it can be set perfectly as wallpaper – Prerna Singhal Sep 18 '15 at 05:14
  • Where did you read that? im thinking that if image is larger than screen it will be cropped to fit, just like your problem. – Nanoc Sep 23 '15 at 09:11

0 Answers0