C#图像从Project Image文件夹加载图像未找到错误

时间:2015-08-26 01:30:56

标签: c# asp.net-mvc bitmap

我只是在我调用该图像的同一个函数中将图像保存在我的项目文件夹中,但问题是我收到错误找不到图像错误。 enter image description here

// Saving image in my project folder.....

** I have the image in my project folder 1.jpg** 

string imageFilePath = @"~/Images/1.jpg";
Bitmap bitmap = (Bitmap)Image.FromFile(imageFilePath);  //load the image file
using (Graphics graphics = Graphics.FromImage(bitmap))
{
    using (Font arialFont = new Font("Arial", 17))
    {
        graphics.DrawString(images.UperName, arialFont, Brushes.Blue, firstLocation);
        graphics.DrawString(images.LowerName, arialFont, Brushes.Red, secondLocation);
    }
}

bitmap.Save(imageFilePath);//save the image file

1 个答案:

答案 0 :(得分:1)

您无法在文件系统中使用虚拟路径“〜/ Images / 1.jpg”。正如leppie所说,你应该使用Server.MapPath将虚拟路径“〜/ Images / 1.jpg”转换为物理路径,如“C:\ filepath \ filename.ext”。