title: OpenCV Unhandled exception when writing a file
body: <p>After trying different things, my program always crashes while saving an image. It reads well the image and I'm able to visualize it but I can't save files (it occurs in all programs that I make with OpenCV while using imwrite). It occurs while debugging in Visual Studio 10.0 with OpenCV 2.1:</p>
  
  <pre><code>Unhandled exception at 0x67570fcd in SR.exe: 0xC0000005: Access violation reading location 0x00000000.
  </code></pre>
  
  <p>Here the code:</p>
  
  <pre><code>Mat imLow;
  
  imLow=imread("Cameraman256.png",0);
  if(!imLow.data)                             
  {
      std::cout&lt;&lt;  "Could not open or find the image" &lt;&lt; std::endl ;
      return -1;
  }
  imwrite( "image.png", imLow);
  </code></pre>
  
  <p>Can anyone tell me how can I fix this? Thank you</p>
  
  <p><strong>UPDATE</strong>: It seems to be a problem with PNG and JPEG format, because the line works while saving in BMP format.</p>