I am trying to make a very simple tile engine. However, using the Bitmap.getpixel(x,y)
is not always matching the color correctly. It seems to be doing fine with 0xFFFFFFFF
, 0xFF000000
, 0xFF189600
, and 0xFF18FF00
, but has a problem with 0xFF186600
. I tried changing it to multiple different similar colors, but it still doesn't seem to be reading it correctly. I am comparing with a simple switch statement. Here is the code for my method
public void LoadLevel(Canvas canvas, int levelName)
{
Bitmap level = BitmapFactory.decodeResource(getResources(), levelName);
Bitmap startTile = BitmapFactory.decodeResource(getResources(), R.drawable.starttile);
canvas.drawColor(Color.WHITE);
int drawX = 0;
int drawY = 0;
for(int y = 0; y < level.getHeight(); y++)
{
for(int x = 0; x < level.getWidth(); x++)
{
switch(level.getPixel(x, y))
{
case 0xFF000000: break;
case 0xFFFFFFFF:
canvas.drawBitmap(startTile, drawX, drawY, null);
break;
case 0xFF189600:
canvas.drawBitmap(startTile, drawX, drawY, null);
break;
case 0xFF18FF00:
canvas.drawBitmap(startTile, drawX, drawY, null);
break;
case 0xFF186600:
canvas.drawBitmap(startTile, drawX, drawY, null);
break;
}
Log.d("Color", Integer.toString(level.getPixel(x, y)));
drawX += 128;
}
drawX = 0;
drawY += 128;
}
}
According to the log, the color is "-15177472". I am not sure what color that actually is though... So I am not sure if -15177472 == 0xFF186600
What am I doing incorrectly to not get the pixel? Is android changing the image? Are there safe colors I am suppose to use?