我使用以下代碼,目的是創建一個半白半黑的圖像並將其放在一個按鈕上。 我的代碼有什麼問題? (後面我們要使用什麼像素是白色的,什麼是黑的更復雜的邏輯,但它應該仍然是黑色和白色)在android中創建圖像並渲染到ImageButton中
int height = 100;
int width = 100;
quadratImage = Bitmap.createBitmap(
width,
height,
Bitmap.Config.ALPHA_8);
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
int color;
if (x< 50){
color = R.color.black;
}
else{
color = R.color.white;
}
quadratImage.setPixel(
x, y, color);
}
}
quadratImage.prepareToDraw();
imageButton.setImageBitmap(quadratImage);
我的顏色定義爲:
<color name="black">#000000</color>
<color name="white">#ffffff</color>
您遇到的問題是什麼? – Asahi 2010-10-24 22:48:52