i'm currently building an app and i want to change the wallpaper. So here is my code. When the user sets the wallpaper i save the path to Shared Preferences.
Display display = getWindowManager().getDefaultDisplay();
SharedPreferences prefs = getBaseContext().getSharedPreferences(PREFS_NAME,0);
if (prefs.contains(d)) {
Bitmap bitmapOrg = BitmapFactory.decodeFile(prefs.getString(d, ""));
int newWidth = display.getWidth();
int newHeight = display.getHeight();
Bitmap resizedBitmap =Bitmap.createScaledBitmap(bitmapOrg, newWidth, newHeight, true);
myWallpaperManager.setBitmap(resizedBitmap);
}
and with that code i got something like this while i want to show the pictures like this
any idea how to do this?
Ok i found out how to do this. First i create a new bitmap
newBmp = Bitmap.createBitmap(display.getWidth(), display.getHeight(), Bitmap.Config.ARGB_8888);
then the original bitmap resized:
Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmapOrg, scaleWidth, scaleHeight, false);
then i call overlay to draw both images together. The first image has the dimensions of the display and the second is the image.
vate Bitmap overlay(Bitmap bmp1, Bitmap bmp2, int left, int imgsize) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.drawBitmap(bmp2, left-(imgsize/2), 15, null);
return bmOverlay;
}
and finally:
myWallpaperManager.setBitmap(newB);