title: Constructing image from Grayvalues
body: <p>I have extracted the Gray Value from an image file (format .3pi) and wrote them in file (Code below)-</p>
  
  <pre><code>public class ImageFile {
  public static void main(String[] args) throws IOException {
      FileInputStream fstream = new FileInputStream ("Z:\\20100204-000083-011.3pi");
      DataInputStream in = new DataInputStream (fstream);
  
      BufferedReader reader = new BufferedReader (new InputStreamReader (in));
      String str = "";
      String temp [];
      int counter = 0, NumberOfColumn = 0, NumberOfRow = 0;
      try {
        while (counter != 3) {
              str = reader.readLine();
              counter ++;
              if (counter == 2) {
                  temp = str.split(" ");
                  NumberOfRow = Integer.valueOf(temp[5].trim()).intValue();
  
              }
              else if (counter == 3) {
                  temp = str.split(" ");
                  NumberOfColumn = Integer.valueOf(temp[3].trim()).intValue();            
              }
          }
      } 
  
      catch (FileNotFoundException e){
          e.printStackTrace();
      }
  
      catch (IOException e) {
          e.printStackTrace();
      }
  
      //System.out.println ("Row : "+NumberOfRow);
      //System.out.println ("Column : "+NumberOfColumn);
  
      int found = 0, CurrentColumn = 0, CurrentRow = 0, GrayValue;
      int image [][] = new int [NumberOfRow][NumberOfColumn];
  
      FileInputStream fstream2 = new FileInputStream ("Z:\\20100204-000083-011.3pi");
      DataInputStream in2 = new DataInputStream (fstream2);
      BufferedReader reader2 = new BufferedReader (new InputStreamReader (in2));
  
      FileWriter fstream3 = new FileWriter("Z:\\Test.txt",true);
      BufferedWriter writer = new BufferedWriter (fstream3);
      while ((str = reader2.readLine()) != null) {            
          str = str.trim();
          temp = str.split(" ");
          if (temp [0].contentEquals("#:Profile:")) {
              CurrentColumn = Integer.valueOf(temp[1].trim()).intValue();
              //System.out.println ("Current Column : "+CurrentColumn);
              found = 1;
              continue;
          }
          else {
              if (found == 1) {
                  CurrentRow = Integer.valueOf(temp[4].trim()).intValue();
                  GrayValue = Integer.valueOf(temp[3].trim()).intValue();
                  image [CurrentRow][CurrentColumn] = GrayValue;                  
              }
          }
      }
      for (int i= 0; i&lt; NumberOfRow; i++){
          for (int j= 0; j&lt; NumberOfColumn; j++){
              writer.write (image [i] [j]+" ");
          }
          writer.write("\n");
      }
      writer.close();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Now, I want to create a jpg/ bmp/ any other image with the Gray value information in Test.txt file. How can I achieve it? Help appreciated.</p>
  
  <p>Zereen</p>