0

I am fairly new with android development. I am trying to take a 8x8 array of integers and make a 8x8 square (64 squares) using canvas and bitmap, a picture below shows what I want to accomplish. Each square would correspond to the index of the integer array, and the color of the square will change depending on the integers(0-255).

Currently, I am just trying to draw the layout of my application, but I am stuck on drawing the array of squares using canvas and bitmap. I have looked at different sources and the following two seems like very close to what I want to do.

source 1: I declared a 2d bitmap variable like this: Bitmap bmp[][] = new Bitmap[8][8] and tried to use a double for loop, but my app crashes because of

Boolean android.graphics.Bitmap.isRecycled() on a null reference

source 2 I tried alexander zak's answer but I am not sure how to draw squares on to the screen using the Bitmap return value.

Any one have any suggestions on how I can accomplish my goal? thanks for all your help.

BOB
  • 151
  • 3
  • 13

1 Answers1

1

Figured it out by:

Create a bitmap objectBitmap bmp = Bitmap.createBitmap(8, 8, bitmap.Config.ARGB_8888)

set each pixels(64) bmp.setPixel(index_of_the_bitmap_x, index_of_the_bitmap_y, int color)using a double for loop or which ever.

Draw a bitmap onto the canvas and scale it to the size of a rectangle: canvas.drawBitmap(bmp, null, destinationRet, null);

BOB
  • 151
  • 3
  • 13