Hello, I'm trying to draw a map from a textfile onto a Bitmap, but the Bitmap is all black
First i load a textfile that looks like this (shortened):
0000000000 (200 width)
0111111110
0111100010
0000111110
0000111000
0000000000
(120 height)
Where "1" is ground and "0" is a wall, 1 should be white and 0 should be black.
Code:
public Map(String map) {
this.map = map;
init();
}
public void init() {
mapArray = new int[WIDTH*HEIGHT];
String[] splitMap = map.split("\n");
int width = splitMap[0].length();
int height = splitMap.length;
int[] colors = new int[WIDTH * HEIGHT];
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
int type = Integer.valueOf(splitMap[y].charAt(x));
setType(x, y, type);
if(type == WALL) {
setColor(x, y, Color.rgb(0, 0, 0), colors);
} else if(type == GROUND) {
setColor(x, y, Color.rgb(255, 255, 255), colors);
} else if(type == GOAL) {
setColor(x, y, Color.rgb(255, 255, 255), colors);
}
}
}
bitmap = Bitmap.createBitmap(colors, WIDTH, HEIGHT, Config.ARGB_8888);
}
public void setColor(int x, int y, int color, int[] colors) {
for(int y1 = 0; y1 < 4; y1++) {
for(int x1 = 0; x1 < 4; x1++) {
colors[(x + x1) + (y + y1) * WIDTH] = color;
}
}
}
public void setPixel(int x, int y, int color) {
for(int y1 = 0; y1 < 4; y1++) {
for(int x1 = 0; x1 < 4; x1++) {
bitmap.setPixel(x + x1, y + y1, color);
}
}
}
public void setType(int x, int y, int type) {
for(int y1 = 0; y1 < 4; y1++) {
for(int x1 = 0; x1 < 4; x1++) {
mapArray[(x + x1) + (y + y1) * WIDTH] = type;
}
}
}
public int getType(int x, int y) {
return mapArray[x + y * WIDTH];
}
public void doDraw(Canvas canvas) {
canvas.drawBitmap(bitmap, 0, 0, null);
}
private final static int WALL = 0;
private final static int GROUND = 1;
private final static int GOAL = 2;
private final static int WIDTH = 800;
private final static int HEIGHT = 480;
private int[] mapArray = null;
private String map = null;
public Bitmap bitmap;