title: GDI+ Generic Error when converting from tif to jpg
body: <p>All of the questions I've seen on SO and other places mention closing or not closing streams as potential problems. If that's not the problem then the existence or rights of directories saving to is the problem. I'm not sure any of that applies here. Partly because this only happens on specific tif files stored in the DB and partly because the code isn't saving or reading a file from the servers file system. But if I point my development machine at the production server it can convert the tif files to a jpg. So it only fails on specific files and it only fails on the production server. </p>
  
  <p>This is from an old library written before me. We did clear out the Temp directory on the windows server recently. Not sure if that would cause any issues but thought I'd throw that info in as well. </p>
  
  <p>GDI fails either on the ConvertFrom line or the FromStream line depending on what's commented out and what's not. </p>
  
  <p>At first I thought maybe the tif files were corrupted but then I was able to use the dev machine to convert. Permissions or directory issues shouldn't be a problem because it works on some tif files. I feel like I'm missing something super obvious. Any help or suggestions to try would be appreciated. I added slashes to the code for Stack Overflow display purposes. The formatting wasn't picking up on the VB comment marker '.</p>
  
  <pre><code>Private Function image2jpg(ByVal dID As Integer) As System.IO.MemoryStream
      Dim sql As String = "SELECT blob FROM [Database].[schema].[table] WHERE dID = @dID"
      Dim params As New DB_Methods.params("@dID", dID)
      Dim img = DB_Methods.sqlQuickGetUSP(sql, "ADMIN", params, False)
      Dim demBits As Byte() = CType(img(0)(0), Byte())
  
  
      //'new code i tried that also fails
      Dim ic As System.Drawing.ImageConverter = New System.Drawing.ImageConverter()
      Dim x As System.Drawing.Bitmap = ic.ConvertFrom(demBits) //'this is where GDI fails
      Dim newImg = x
      //'Throw New Exception(demBits.Length &amp; " " &amp; ms.Length)
  
      //'Original code that was failing
      //'Dim ms As System.IO.MemoryStream = New MemoryStream(demBits)
      //'Dim tmpImg As System.Drawing.Image = System.Drawing.Image.FromStream(ms)'this is where GDI fails
      //'Dim newImg As Drawing.Image = New Drawing.Bitmap(tmpImg, tmpImg.Width, tmpImg.Height)
  
      Dim newStream As New MemoryStream
      newImg.Save(newStream, ImageFormat.Jpeg)
      Return newStream
  End Function
  </code></pre>