onDraw
method, which looks like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override protected void onDraw(Canvas canvas) { | |
canvas.drawColor(Color.WHITE); | |
Paint paint = new Paint(); | |
paint.setStyle(Style.FILL); | |
for (int i = 0; i < model.size; i++) { | |
for (int j = 0; j < model.size; j++) { | |
int level = model.state[i][j]; | |
int blockSize = (int) Math.pow(2, level); | |
int pixelBlockSize = blockSize * model.SMALLEST_SIZE; | |
if ((i % blockSize) == 0 && (j % blockSize) == 0) { | |
Log.v(TAG, "level, x, y, size are " + (model.maps.length - level - 1) + ", " + (i / blockSize) + ", " + (j / blockSize) + ", " + model.maps[level].getHeight()); | |
paint.setColor(model.maps[model.maps.length - level - 1].getPixel(i / blockSize, j / blockSize)); | |
Log.v(TAG, "level is " + level + ", pixelBlockSize to circle is " + pixelBlockSize); | |
canvas.drawCircle(i * model.SMALLEST_SIZE + pixelBlockSize / 2, j * model.SMALLEST_SIZE + pixelBlockSize / 2, pixelBlockSize / 2, paint); | |
} | |
} | |
} | |
} |
onDraw
method simply load the bitmap, which internally is just a memcpy and takes only a few millisecond. In other words, you don't redraw what is not changed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override protected void onDraw(Canvas canvas) { | |
canvas.drawColor(Color.WHITE); | |
Paint paint = new Paint(); | |
canvas.drawBitmap(model.map, 0, 0, paint); | |
} |
onDraw
method. The following code snippet is what I used in my program.
When I create a Bitmap:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map = Bitmap.createBitmap(size * SMALLEST_SIZE, size * SMALLEST_SIZE, Bitmap.Config.ARGB_8888); | |
canvas = new Canvas(map); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paint.setColor(Color.WHITE); | |
canvas.drawRect(x, y, x + size, y + size, paint); | |
paint.setColor(color); | |
canvas.drawCircle(x + size / 2, y + size / 2, size / 2, paint); |
No comments:
Post a Comment