【发布时间】:2021-08-16 04:59:08
【问题描述】:
我想知道是否有一种方法可以使用 FileOutputStream 类创建和写入便携式 ASCII P2 灰度图文件。 (我需要使用这个类)
这是我到目前为止所做的,但我认为这是错误的,因为我无法使用此查看器打开文件: https://smallpond.ca/jim/photomicrography/pgmViewer/index.html
public class Main {
public static void main(String args[]){
try{
FileOutputStream fos = new FileOutputStream("picture.pgm");
//create .pgm header
//P2
fos.write('P');
fos.write('2');
//500x200 pixel
fos.write(500);
fos.write(200);
//create black image
for(int i=0; i< 500; i++){
for(int k=0; k< 200; k++){
fos.write(0);
}
}
fos.close();
}catch(IOException e){
System.out.println(e);
}
}
}
【问题讨论】:
标签: java fileoutputstream