convert text file into binnary format bitmap using java

Solutions on MaxInterview for convert text file into binnary format bitmap using java by the best coders in the world

showing results for - "convert text file into binnary format bitmap using java"
Miracle
16 Jan 2016
1import java.awt.image.BufferedImage;
2import java.io.DataInputStream;
3import java.io.EOFException;
4import java.io.File;
5import java.io.FileInputStream;
6import java.io.IOException;
7import javax.imageio.ImageIO;
8public class Test3 {
9public static void main(String[] args) throws IOException {
10  
11 
12int i =0;
13int w = 320;
14int h = 240;
15int  imageData[] = new int[w * h];
16  
17FileInputStream file_input = new FileInputStream ("D:\\abc.bin");
18DataInputStream data_in    = new DataInputStream (file_input );
19  
20while (true) {
21  try {
22  imageData[i++] = data_in.readInt ();
23     
24  }
25  catch (EOFException eof) {
26    System.out.println ("End of File");
27    break;
28  }
29}
30BufferedImage finalImage;
31finalImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);//TYPE_INT_ARGB
32finalImage.setRGB(0, 0, w, h, imageData, 0 ,w);
33ImageIO.write(finalImage, "bmp", new File("D:\\abc.bmp"));
34  
35}
36}
37
similar questions