当我尝试创建一个新的位图图像以传递给方法时,我正面临着这个奇怪的问题。 在
处发生异常位图bm =新位图(“images / cat.jpg”);
我尝试使用各种尺寸的各种图像来尝试测试是否是文件大小问题,但是结果只有项目中的1个现有图像可以工作(这是猫的图片)。
所有其他图像都返回错误“参数无效”。我尝试重建项目并允许读取权限,但我仍然无法使其工作。
System.ArgumentException was unhandled
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Bitmap..ctor(String filename)
at Image_Authentication_Final.RegistrationForm.btnRegister_Click(Object sender, EventArgs e) in c:\Users\Acc\Desktop\Image Authentication Final\Image Authentication Final\RegistrationForm.cs:line 176
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at MetroFramework.Controls.MetroButton.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Image_Authentication_Final.Program.Main() in c:\Users\Acc\Desktop\Image Authentication Final\Image Authentication Final\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
答案 0 :(得分:0)
如果文件位于网络驱动器上并且刚刚写入,则文件的创建者关闭文件后,可能需要一两秒才能将文件从独占中释放。
答案 1 :(得分:0)
忘记添加。众所周知,.NET在处理位图和图像方面很奇怪,并且需要释放或处置图像资源。反复执行图像操作而没有释放它们会导致问题。
在流程浏览器中检查流程的句柄计数。
对于用于图像处理的服务器端甚至桌面应用程序,我已将图像写入磁盘,然后运行imagemagick.exe命令行来处理图像并等待图像文件输出被写入。它允许imagemagick在一个进程中启动,执行图像操作和退出所有操作,而不会阻塞.net的内存或句柄。