我使用以下代码来创建一个半白半黑的图像并将其放在按钮上。我的代码有什么问题?(后面我们想使用更复杂的逻辑来判断哪些像素是白色的,哪些是黑色的,但它仍然应该是黑白的)
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>