从android中的二维布尔数组中绘制图像

时间:2015-06-18 20:45:19

标签: android android-bitmap

我有两维整数数组(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中做到这一点。

1 个答案:

答案 0 :(得分:1)

我没有测试,但这可能会有所帮助:

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));
        }
}
相关问题