I want to set home wallpaper with white bitmap:
Bitmap bitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(0xfff);
WallpaperManager wall = WallpaperManager.getInstance(this);
try {
wall.setBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
And the wallpaper becomes black. What’s wrong is here?
My first guess would be your color choice, assuming this is the value in your actual code and not edited.
Color ints in java take the form ARGB, so
Color.WHITEis0xFFFFFFFF,Color.BLUEis0xFF0000FF, etc.The color in your code (
0xFFF) would expand to0x00000FFFwhich is Blue with a little green mixed in, but the alpha channel is zero, so theCanvasis basically written with a transparent color.If you are using standard colors, I would stick to the constants in the
Colorclass as parameters here, but if you want to define the color yourself, remember to place the full color or useCanvas.drawRGB()instead.