I'm trying to convert a batch of .pngs to .jpgs, as in this question:
For Each file As String In Directory.EnumerateFiles(path).Where(Function(s) s.EndsWith(".png"))
Dim newfile As String = IO.Path.Combine(newpath, IO.Path.GetFileNameWithoutExtension(file) & ".jpg")
Using png As Bitmap = Bitmap.FromFile(file)
Using jpg As New Bitmap(png.Width, png.Height)
Using g As Graphics = Graphics.FromImage(jpg)
g.Clear(Color.FromArgb(255, 212, 208, 200))
g.DrawImageUnscaled(png, 0, 0)
jpg.Save(newfile, ImageFormat.Jpeg)
End Using
End Using
End Using
Next
The call to jpg.Save
, however, with a "generic error" in GDI+. Originally outside of the innermost Using
statement, I moved the call inwards as per this answer, but it didn't change anything. I have verified that newfile
contains a valid path, and that the program has write access to the directory. What am I missing?