White bitmap in android
Asked Answered
W

2

8

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?

Wacky answered 10/12, 2012 at 22:42 Comment(1)
What is the value of WIDTH and HEIGHT you are using?Downwash
F
9

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.WHITE is 0xFFFFFFFF, Color.BLUE is 0xFF0000FF, etc.

The color in your code (0xFFF) would expand to 0x00000FFF which is Blue with a little green mixed in, but the alpha channel is zero, so the Canvas is basically written with a transparent color.

If you are using standard colors, I would stick to the constants in the Color class as parameters here, but if you want to define the color yourself, remember to place the full color or use Canvas.drawRGB() instead.

Foldboat answered 10/12, 2012 at 23:15 Comment(0)
T
23

Just add bitmap.eraseColor(Color.WHITE); as second line

Thorvald answered 18/10, 2015 at 16:48 Comment(0)
F
9

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.WHITE is 0xFFFFFFFF, Color.BLUE is 0xFF0000FF, etc.

The color in your code (0xFFF) would expand to 0x00000FFF which is Blue with a little green mixed in, but the alpha channel is zero, so the Canvas is basically written with a transparent color.

If you are using standard colors, I would stick to the constants in the Color class as parameters here, but if you want to define the color yourself, remember to place the full color or use Canvas.drawRGB() instead.

Foldboat answered 10/12, 2012 at 23:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.