title: Converting double to unsigned char?
body: <p>I'm trying to convert a matrix of (doubles) into an unsigned char so I can then write to a .pmg file... But it isn't working.</p>
  
  <pre><code>void writePNG(vector&lt;double&gt;&amp; matrix)
  {
  vector&lt;unsigned char&gt; image;
  ofstream myfile;
  
  myfile.open("newFile.txt", ios::out); // writing to .txt file for now for testing.
  
  if(!myfile.is_open())
  {
      cout &lt;&lt; "Cannot open file";
  }
  for(int i=0; (i &lt; 512*512); i++)
  {
      image[i] = (unsigned char) matrix[i];
  }
  
  myfile.close();
  }
  </code></pre>
  
  <p>It won't convert the data. Any ideas?? Thanks :)</p>