0
有很多關於閱讀.pgm圖像的帖子,但是沒有或幾乎大約有生成一個來自數組。從數組中生成圖像.pgm
有很多關於閱讀.pgm圖像的帖子,但是沒有或幾乎大約有生成一個來自數組。從數組中生成圖像.pgm
好了,所以我想通了如何將二維數組轉換成PGM文件:
try{
//specify the name of the output..
FileWriter fstream = new FileWriter("output.pgm");
//we create a new BufferedWriter
BufferedWriter out = new BufferedWriter(fstream);
//we add the header, 128 128 is the width-height and 63 is the max value-1 of ur data
out.write("P2\n# CREATOR: XV Version 3.10a Rev: 12/29/94\n128 128\n63\n");
//2 loops to read the 2d array
for(int i = 0 ; i<tabDecode.length;i++)
for(int j = 0 ; j<tabDecode[0].length;j++)
//we write in the output the value in the position ij of the array
out.write(tabDecode[i][j]+" ");
//we close the bufferedwritter
out.close();
}
catch (Exception e){
System.err.println("Error : " + e.getMessage());
}
什麼陣列? – VGR
@VGR它是從0到64的值的二維數組,我回答了我的問題btw – Ben