📌  相关文章
📜  使用java代码示例将文本文件转换为二进制格式位图

📅  最后修改于: 2022-03-11 14:52:36.793000             🧑  作者: Mango

代码示例1
import java.awt.image.BufferedImage;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Test3 {
public static void main(String[] args) throws IOException {
  
 
int i =0;
int w = 320;
int h = 240;
int  imageData[] = new int[w * h];
  
FileInputStream file_input = new FileInputStream ("D:\\abc.bin");
DataInputStream data_in    = new DataInputStream (file_input );
  
while (true) {
  try {
  imageData[i++] = data_in.readInt ();
     
  }
  catch (EOFException eof) {
    System.out.println ("End of File");
    break;
  }
}
BufferedImage finalImage;
finalImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);//TYPE_INT_ARGB
finalImage.setRGB(0, 0, w, h, imageData, 0 ,w);
ImageIO.write(finalImage, "bmp", new File("D:\\abc.bmp"));
  
}
}