Create a chess like bitmap with random colors. - Android Graphics

Android examples for Graphics:Bitmap Color

Description

Create a chess like bitmap with random colors.

Demo Code


//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Color;
import java.util.Random;

public class Main {
    /**//ww w.  j av a  2 s .c  om
     * Create a chess like bitmap with random colors.
     *
     * @param config Bitmap config.
     * @return A bitmap.
     */
    public static Bitmap createChessColorBitmap(Bitmap.Config config) {
        int values[] = new int[16 * 16];
        int p = 0;
        Random random = new Random(10);
        for (int y = 0; y < 16; y++) {
            for (int x = 0; x < 16; x++) {
                int grey = random.nextInt(256);
                values[p] = Color.argb(255, grey, grey, grey);
                p++;
            }
        }
        return Bitmap.createBitmap(values, 16, 16, config);
    }
}

Related Tutorials