【发布时间】:2014-04-11 09:51:26
【问题描述】:
我是 C# 的新手,但遇到以下问题。
我必须检索一个 hello.jpg 文件,该文件位于我的项目的子目录中。
所以我认为我必须将相对路径放入一个字符串中,然后使用这个字符串来创建一个 Image 对象或类似的东西。
你能帮帮我吗?
编辑:
我已将此代码插入我的班级:
private System.Web.HttpServerUtility server;
protected System.Drawing.Image _backgroundImg = System.Drawing.Image.FromFile(server.MapPath("~/Path/Relative/To/Root.jpg"));
但我收到以下错误消息:
错误 76 字段初始化程序无法引用非静态字段, 方法或属性 'PdfReport.iTextDocumentBase.server' C:\Develop\EarlyWarning\public\Implementazione\Ver2\PdfReport\iTextDocumentBase.cs 44 87 PdfReport 错误 77 字段初始值设定项无法引用非静态字段, 方法或属性 'PdfReport.iTextDocumentBase.server' C:\Develop\EarlyWarning\public\Implementazione\Ver2\PdfReport\iTextDocumentBase.cs 44 87 PdfReport
为什么?有什么办法可以解决?
【问题讨论】:
-
你想在页面中显示图片吗?
-
你能显示一些代码吗?
-
如果您的图像名称是 hello.jpg 为什么要为 Root.jpg 放置路径?