Trying to make a random pixel in a bitmap a new color, but it is giving an error why

139 views Asked by At

It is in a view so the setBackground method should be fine, and I am passing Color.BLUE, which is definitely a proper int.

    public void changeRandomPixel(int color) 
    {
         Bitmap resizedBitmap = Bitmap.createScaledBitmap(intialBitmap, 10, 10, true);
            int[] pixels = new int[resizedBitmap.getHeight()* resizedBitmap.getWidth()];
            resizedBitmap.getPixels(pixels, 0,  resizedBitmap.getWidth(), 0, 0,  resizedBitmap.getWidth(),  resizedBitmap.getHeight());

            Random rand = new Random();

            pixels[rand.nextInt(100)] = color;          

            resizedBitmap.setPixels(pixels, 0,  resizedBitmap.getWidth(), 0, 0,  resizedBitmap.getWidth(),  resizedBitmap.getHeight());

            Drawable background = new BitmapDrawable(getResources(), resizedBitmap);
            setBackground(background);
    }
0

There are 0 answers