c# - 如何在 C# 中将图像从文件路径转换为位图

标签 c#

Bitmap  bmp = new Bitmap("D:\1.jpg");

我得到的异常是:

parameter is not valid.

我该如何解决这个问题?

最佳答案

这通常是可行的,您是否使用转义字符来转义转义字符? 示例:

Bitmap bm = new Bitmap("D:\\newfolder\\1.jpg");
//Notice the \\ the second \ escapes the first

或者像这样转义:

Bitmap bm = new Bitmap(@"D:\newfolder\1.jpg");
//Notice the @ in front of the string, that means ignore the escape characters

您的原始字符串不会对此进行转义,因此会插入一个换行符 (\n)。

关于c# - 如何在 C# 中将图像从文件路径转换为位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43866266/

相关文章:

c# - 在用户注册身份时为用户设置角色的正确方法

c# - 使用反射按名称获取方法时如何重构?

c# - JWT 访问 token 与刷新 token (创建)

c# - Azure Function 中的复杂对象应用设置

c# - WPF 等待从 UI 线程切换

c# - 为什么 "K".Length 给我错误的结果?

c# - 仅通过提供字符串名称获取属性

c# - 尝试检查 urlreferrer 是否为空

c# - QueryOver 查找别名字符串

c# - 如何将目录中的最后一个文件添加到 List<string> 中?