GDI+、PNG 图像转 UNC 时发生一般错误

发布于 2024-10-10 16:36:55 字数 1196 浏览 1 评论 0原文

通常我不会在论坛上写东西,只是阅读我需要的信息。 这次我遇到了很大的问题,需要专家的帮助。

我想将 PictureBox 中的图像保存到文件中。

当我使用

Image.Save("X:\\Files\\logo.png");

但我需要将图像保存到 UNC 位置时它可以工作。 因此,从 X:\Files 创建了 UNC

当我尝试保存图像时,

Image.Save("\\\\\PC\\Files\\logo.png");

我收到愚蠢的 GDI+ 错误,没有任何信息。

我​​尝试使用 MemoryStream 保存它,但没有解决任何问题。 我尝试了 4 个小时,但没有成功。

如果我将 netvork 驱动器 \\PC\files 映射到驱动器盘符,可以说 L:\ 然后将图像另存为

Image.Save("L:\\logo.png"); // it works !

“确定”,你小子怎么了?再次..

Image.Save("X:\\Files\\logo.png");          // WORKS
Image.Save("\\\\PC\\Files\\logo.png");    // GDI+ ERROR
Image.Save("L:\\logo.png");  // DOES THE JOB (it is network drive from \\pc\files)

好吧,现在您会问我在共享文件夹上创建了哪些权限。 我添加了用户 Everyone 并设置了写入、读取和执行的权限。

问题是,实际上我想将图像保存到 NAS 驱动器,所以我不确定它具有什么 Sabma 安全权限(每个人、访客都不知道),或者换句话说,它并不像单击共享文件夹并播放那么简单具有权限..

我怎样才能解决这个有缺陷的实现?我尝试了 Image.Clone()、MemoryStrean 以及我在 Uncle Google 中找到的所有东西,但没有任何效果。我认为问题不在于无法访问的图像,但它与 UNC 位置的权限有关,但只是不知道为什么如果我在没有特殊用户登录的情况下创建网络驱动器它会起作用。我只是不能告诉客户创建网络驱动器它必须与 UNC 路径一起使用!

Ussualy I don't write stuff to forums just read info that i need.
This time I've got big problems and I need help from expert.

I would like to save image from PictureBox to file.

It works when I use

Image.Save("X:\\Files\\logo.png");

But I need to save Image to UNC location.
So created UNC from X:\Files

When I try to save Image as

Image.Save("\\\\\PC\\Files\\logo.png");

I get stupid GDI+ error without any info..

I tried saving it using MemoryStream and nothing is resolved..
I am trying it for 4hours and no sucess..

If I map netvork drive \\PC\files to drive letter lets say L:\
and then save image as

Image.Save("L:\\logo.png"); // it works !

OK what is with you boy? Again..

Image.Save("X:\\Files\\logo.png");          // WORKS
Image.Save("\\\\PC\\Files\\logo.png");    // GDI+ ERROR
Image.Save("L:\\logo.png");  // DOES THE JOB (it is network drive from \\pc\files)

Ok now you will ask me what perrmisions I created on Shared folder.
I added user Everyone and set permissions to write,read&execute.

Problem is that actually I would like to save Images to NAS drive so I am not sure what Sabma security permissions it has (everyone,guest, don't know) or in other words it is not as simple as clicking on Shared folder and play with permissions..

How can I resolve this buggy implementation? I tried Image.Clone(), MemoryStrean and all the stuff I found with Uncle Google but nothing does the job I think that problem isn't in unaccessable Image but it has something to do with permissions on UNC location but just don't know why it works if i create Network Drive with no special user login.. I just can't say to customer to create Network Drive it has to work with UNC path!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杯别 2024-10-17 16:36:55

我想说你只是算错了你的反斜杠 - 应该是 4 个,而不是 5 个。尝试:

Image.Save("\\\\PC\\Files\\logo.png");

I'd say you just miscounted your backslashes - there should be 4, not 5. Try:

Image.Save("\\\\PC\\Files\\logo.png");
人事已非 2024-10-17 16:36:55

谢谢马克的评论。我没有 5 个反斜杠,但我做了一些更愚蠢的事情...

TextBox1.Text = "\\\\\\\\PC\\Files"; // through GUI I add "\\\\PC\Files"

然后

string path = TextBox1.Text;    
Image.Save(path + "\\" filename");

你可以看到路径中的字符串是“\\\\PC\Files”!错误的! :=)
它必须是 \\ 所以解决方案是

TextBox1.Text="\\\\PC\\Files"; // or if I add this string by GUI "\\PC\Files"

在我愚蠢的文本框中输入之后的内容。

if (path.StartsWith("\\\\\\\\") || path.Contains(":"))
{
   // Problem was that in TextBox were really 4 backslashes so it jumps here
   image.Save(path,ImageFormat.Png); 
   // and because string started as "\\\\" it throws GDI+ error
}
else
{
   string path2= Directory.GetCurrentDirectory()+"\\"+path;
   image.Save(path2, System.Drawing.Imaging.ImageFormat.Png);
}

是的,我是个白痴 :=)

我确实修复了,它应该是这样的 :=)
很抱歉我在 stackoverflow 上发送了垃圾邮件。

Thank you Mark for comment.. I didn't have 5 backslashes but I did something more stupid...

TextBox1.Text = "\\\\\\\\PC\\Files"; // through GUI I add "\\\\PC\Files"

and then

string path = TextBox1.Text;    
Image.Save(path + "\\" filename");

As you can se the string in path was "\\\\PC\Files"! Wrong! :=)
It has to be \\ so solution is

TextBox1.Text="\\\\PC\\Files"; // or if I add this string by GUI "\\PC\Files"

And something that follows my stupid input into text box.

if (path.StartsWith("\\\\\\\\") || path.Contains(":"))
{
   // Problem was that in TextBox were really 4 backslashes so it jumps here
   image.Save(path,ImageFormat.Png); 
   // and because string started as "\\\\" it throws GDI+ error
}
else
{
   string path2= Directory.GetCurrentDirectory()+"\\"+path;
   image.Save(path2, System.Drawing.Imaging.ImageFormat.Png);
}

Yeah I am an Idiot :=)

i did fix and it is the way it should be :=)
I am sorry that I am spamming stackoverflow.

独守阴晴ぅ圆缺 2024-10-17 16:36:55

我认为这不是代码问题,这是由于安装的组件造成的,我也遇到了同样的问题,在常规服务器上上传后自行解决。

I think it is not a code problem, it is due to installed components, I also experienced the same issue and is solved by self after uploading on a regular server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文