Domanda

Come posso convertire una matrice 2D di INT in un PNG in scala di grigi. In questo momento ho questo:

    BufferedImage theImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    for(int y = 0; y<100; y++){
        for(int x = 0; x<100; x++){
            theImage.setRGB(x, y, image[y][x]);
        }
    }
    File outputfile = new File("saved.bmp");
    ImageIO.write(theImage, "png", outputfile);

Ma l'immagine esce blu. Come posso renderlo una scala di grigi.

Immagine [] [] contiene INT che vanno da 0-256.

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top