保存图像:GDI 中发生一般错误。 (vb.net)
我需要在从 OFD 打开图像后保存图像。 这是我的代码 atm:
Dim ofd As New OpenFileDialog
ofd.Multiselect = True
ofd.ShowDialog()
For Each File In ofd.FileNames
Image.FromFile(File).Save("C:\Users\Jonathan\Desktop\e\tmp.png", Imaging.ImageFormat.png)
Next
并在行 Image.FromFile(File).Save("C:\Users\Jonathan\Desktop\e\tmp.png", Imaging.ImageFormat.png)
上出现错误。
(注意:应用程序将基于此构建,因此这只是我的第一个代码,需要保存而不是复制)
I need to save an image after opening it in from an OFD.
This is my code atm:
Dim ofd As New OpenFileDialog
ofd.Multiselect = True
ofd.ShowDialog()
For Each File In ofd.FileNames
Image.FromFile(File).Save("C:\Users\Jonathan\Desktop\e\tmp.png", Imaging.ImageFormat.png)
Next
And on the line Image.FromFile(File).Save("C:\Users\Jonathan\Desktop\e\tmp.png", Imaging.ImageFormat.png)
it comes up with the error.
(note: the application will be built on so that's just my first code and it will need to be saved not copied)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我会检查两件事:
存在
这个目录
I'd check two things:
exists
this directory
打开或保存图像会锁定文件。覆盖此文件需要您首先对持有锁的 Image 对象调用 Dispose()。
我不太理解你的代码,但你必须这样做:
Using 语句确保 img 对象被释放并释放文件锁。
Opening or saving an Image puts a lock on the file. Overwriting this file requires you to first call Dispose() on the Image object that holds the lock.
I don't really understand your code but you'd have to do it this way:
The Using statement ensures that the img object is disposed and the file lock is released.
图像加了一把锁。
例如,我使用此缓冲区图像保存到内存流中。
The Image puts a lock.
For example, i used this buffer images to save in to a memorystream.
原因之一是您加载主图像的流(MemoryStream 或任何其他流)已被释放!
这样的情况:
这是一个将字节数组转换为位图的扩展方法,但是using语句会处理内存流,这总是会导致这个错误:
One reason of this is that the stream (MemoryStream or any other stream) that you have loaded the main image from has been disposed!
Such this case:
This is an extension method that converts a byte array to a bitmap, but using statement will dispose the memory stream, this will cause this error always:
出现此问题似乎是因为
Image.Drawing.FromFile()
方法锁定了打开的文件!我遇到了同样的问题,并使用以下解决方法解决了此问题。
解决方法包括将
NEW.jpeg
的文件中,img
对象以释放它。 code> 和
Update()
方法,我调用一个特定的方法来更改照片的拍摄日期。这是当相机日期未正确初始化时重命名照片的拍摄日期的程序的一部分。
This problem seems occuring because
Image.Drawing.FromFile()
method lock opened file !I have encountered same problem and I have resolved this issue using following workaround.
The workaround consist to
NEW.jpeg
img
object to release itBetween
OpenFile()
andUpdate()
methods, I call a specific method to change capture's date of a photo.This is part of a program that rename capture's date of photos when camera's date has not been initalized correctly.