Search code examples
javaandroidxmlwallpaper

Wallpapers are auto cropped after applying


I compiled a wallpaper app from a source code, inserted some 1230x720 pictures, But when I applied the walls using that app, they always get cropped automatically. What should I change in the code to apply at the original size and resolution?

Here's an example: 1.Original Picture: https://i.sstatic.net/ziSBt.jpg

2.After applying as an wallpaper using my app: https://i.sstatic.net/19xMQ.jpg

Source code: blog.blundell-apps.com/set-phone-wallpaper/

Thanks

EDIT: this code in HeavyLifter.java seems to be the culprit, how do I change it to "Fit the screen resolution"?

private Bitmap getImage(int resourceId) {
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, null);
    Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, manager.getDesiredMinimumWidth(),   manager.getDesiredMinimumHeight(), true);
    bitmap.recycle();
    bitmap = null;
    return scaledBitmap;
}

Solution

  • The aspect ratio of the image (720x1230) and manager.getDesiredMinimumWidth() to manager.getDesiredMinimumHeight() (720x1280) are not the same and so the image gets distorted.

    So eighter provide a image with a fitting aspect ratio or crop the image before applying the scaling operation