从 android 中的二维布尔数组绘制图像
draw image from two dimensional boolean array in android
我有二维整数数组 (0/1),我想在我的 android 应用程序中将其转换为图像。
任何人都可以指导我如何做到这一点,我不知道也无法从研究中得到任何东西。
我已尝试在 java 桌面应用程序中执行此操作,如下所示
image = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
// Go through the array and set the pixel color on the BufferedImage
// according to the values in the array.
for(int i=0;i<WIDTH;i++){
for(int j=0;j<HEIGHT;j++){
// If the point is in the Set, color it White, else, color it Black.
if(values[i][j]) image.setRGB(i, j, Color.YELLOW.getRGB());
if(!values[i][j]) image.setRGB(i, j, Color.PINK.getRGB());
}
}
但我不知道如何在 android 中做到这一点。
我没有测试,但这可能会有所帮助:
Bitmap image = Bitmap.createBitmap(WIDTH, HEIGHT, Config.ARGB_8888);
for(int i=0;i<WIDTH;i++){
for(int j=0;j<HEIGHT;j++){
if(values[i][j]) image.setPixel(i, j, Color.argb(a, r, g, b));
if(!values[i][j]) image.setPixel(i, j, Color.argb(a, r, g, b));
}
}
我有二维整数数组 (0/1),我想在我的 android 应用程序中将其转换为图像。 任何人都可以指导我如何做到这一点,我不知道也无法从研究中得到任何东西。 我已尝试在 java 桌面应用程序中执行此操作,如下所示
image = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
// Go through the array and set the pixel color on the BufferedImage
// according to the values in the array.
for(int i=0;i<WIDTH;i++){
for(int j=0;j<HEIGHT;j++){
// If the point is in the Set, color it White, else, color it Black.
if(values[i][j]) image.setRGB(i, j, Color.YELLOW.getRGB());
if(!values[i][j]) image.setRGB(i, j, Color.PINK.getRGB());
}
}
但我不知道如何在 android 中做到这一点。
我没有测试,但这可能会有所帮助:
Bitmap image = Bitmap.createBitmap(WIDTH, HEIGHT, Config.ARGB_8888);
for(int i=0;i<WIDTH;i++){
for(int j=0;j<HEIGHT;j++){
if(values[i][j]) image.setPixel(i, j, Color.argb(a, r, g, b));
if(!values[i][j]) image.setPixel(i, j, Color.argb(a, r, g, b));
}
}