Reputation: 13
i have two dimensional array of integers (0/1), and i want to convert it to image in my android application. can any one guide me how to do that, i have no idea and couldn't get anything from researches. i have try to do that in java desktop application as follow
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());
}
}
but i don't know how to do that in android.
Upvotes: 1
Views: 392
Reputation: 11891
I didn't test but this may help:
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));
}
}
Upvotes: 1