【发布时间】:2011-07-28 14:38:05
【问题描述】:
我正在尝试将一批 .pngs 转换为 .jpgs,如 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
但是,对 jpg.Save 的调用在 GDI+ 中出现“一般错误”。最初在最里面的Using 语句之外,我按照this answer 向内移动了调用,但它没有改变任何东西。我已验证 newfile 包含有效路径,并且程序具有对该目录的写访问权限。我错过了什么?
【问题讨论】: