简体   繁体   English

C#位图。保存将图像保存到其他位置作为路径

[英]C# Bitmap.Save saves image to other location as path

I'm doing a simple image resize and on the final I want to save it like: 我正在做一个简单的图像调整大小,最后我想像这样保存它:

path = "C:\\new_image.jpg";
img.Save(path, jpegCodec, encoderParams);

The problem is it saves to "....... \\Users\\Ervin\\AppData\\Local\\VirtualStore\\" . 问题是它保存到“ ....... \\ Users \\ Ervin \\ AppData \\ Local \\ VirtualStore \\”中。 What did I do wrong or what did I miss out? 我做错了什么或错过了什么?

UPDATE: I changed the path to an other folder, and it works. 更新:我将路径更改为另一个文件夹,并且可以工作。 it seems I can't save to C:\\ only. 看来我不能只保存到C:\\。

The resion for this is the user you are running as does not have write permissions to write directly to the C: drive this was new to either Win7 or Vista I am not shure which. 这样做的理由是您所运行的用户没有写许可权,无法直接写到C:驱动器,这对Win7或Vista来说都是新的,我不知道这是什么。

You can solve this by: 您可以通过以下方法解决此问题:

  1. Saving in a directory other than the root of C: 保存在C的根目录以外的目录中:
  2. Changing the permissions on the C: drive so people other than the administrators group have write access. 更改C:驱动器上的权限,以便管理员组以外的其他人具有写访问权限。
  3. Run your program with elevated privileges. 以提升的特权运行程序。

....... \\Users\\Ervin\\AppData\\Local\\VirtualStore\\ was added to help fix legacy applications when you updated. ....... \\ Users \\ Ervin \\ AppData \\ Local \\ VirtualStore \\已添加,以帮助您在更新时修复旧版应用程序。 You may also notice a lot of entries in the "Program Files" in the virtual store. 您可能还会注意到虚拟存储中“程序文件”中的许多条目。 these are programs trying to write to their own directory in program files instead of %LOCALAPPDATA% like they should. 这些程序试图写入程序文件中自己的目录,而不是像应该的那样写入%LOCALAPPDATA%。

This was introduced in Vista, called Virtualization : 这是在Vista中引入的,称为Virtualization

File virtualization addresses the situation where an application relies on the ability to store a file, such as a configuration file, in a system location typically writeable only by administrators. 文件虚拟化解决了应用程序依赖于将文件(例如配置文件)存储在通常只能由管理员写入的系统位置中的情况。 Running programs as a standard user in this situation might result in program failures due to insufficient levels of access. 在这种情况下,以标准用户身份运行程序可能会由于访问级别不足而导致程序失败。

When an application writes to a system location only writeable by administrators, Windows then writes all subsequent file operations to a user-specific path under the Virtual Store directory, which is located at %LOCALAPPDATA%\\VirtualStore. 当应用程序向管理员只能写的系统位置写入文件时,Windows随后会将所有后续文件操作写入位于%LOCALAPPDATA%\\ VirtualStore的Virtual Store目录下用户特定的路径。 Later, when the application reads back this file, the computer will provide the one in the Virtual Store. 稍后,当应用程序读回该文件时,计算机将在虚拟存储中提供该文件。 Because the Windows security infrastructure processes the virtualization without the application's assistance, the application believes it was able to successfully read and write directly to Program Files. 由于Windows安全基础结构无需应用程序的帮助即可处理虚拟化,因此应用程序认为它能够成功地直接读取和写入程序文件。 The transparency of file virtualization enables applications to perceive that they are writing and reading from the protected resource, when in fact they are accessing the virtualized version. 文件虚拟化的透明性使应用程序实际上在访问虚拟化版本时就可以感知到它们正在从受保护的资源写入和读取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM