C# 将图像保存到服务器上

C# 将图像保存到服务器上,c#,model-view-controller,C#,Model View Controller,我想将旋转图像保存到服务器上 我找到了一些解决办法,但不起作用。。 更新 图像路径的格式为xml。。 代码如下: public Boolean saveRotateImg(string path) { string new_path="/Job_Files/"+Job_ID+"/"+GroupName+"/Images/"+path; using (Image image = Image.FromFile(new_path)) { //rotate t

我想将旋转图像保存到服务器上 我找到了一些解决办法,但不起作用。。 更新

图像路径的格式为xml。。 代码如下:

public Boolean saveRotateImg(string path) 
{
    string new_path="/Job_Files/"+Job_ID+"/"+GroupName+"/Images/"+path;
    using (Image image = Image.FromFile(new_path)) 
    {
        //rotate the picture by 90 degrees and re-save the picture as a Jpeg
        image.RotateFlip(RotateFlipType.Rotate90FlipNone);
        System.IO.File.Delete(path);
        image.Save(output, System.Drawing.Imaging.ImageFormat.Jpeg);
        image.Dispose();
    }
}

有人能建议怎么做或其他方法吗?

根据上面的评论,应该是这样的:

public Boolean saveRotateImg(string path) 
{
    string new_path="/Job_Files/"+Job_ID+"/"+GroupName+"/Images/"+path;
    // Load the image from the original path
    using (Image image = Image.FromFile(path)) 
    {
        //rotate the picture by 90 degrees and re-save the picture as a Jpeg
        image.RotateFlip(RotateFlipType.Rotate90FlipNone);

        // Save the image to the new_path
        image.Save(new_path, System.Drawing.Imaging.ImageFormat.Jpeg);
    }
    System.IO.File.Delete(path);
}
尽管您必须确保变量
path
new\u path
包含图像的完整路径+文件名


编辑:我已删除图像。Dispose(),因为使用
将处理此问题。此外,我还将
System.IO.File.Delete(path)
调用替换为例程末尾,不确定是否需要这样做,但在这种情况下,它将永远不会影响图像的使用。

您可以添加一些详细信息吗?例如,新的路径是图像必须存储到的位置吗?这也是图像的来源吗?当然,“不工作”的确切含义是什么?@RFerwerda请检查更新您正在尝试从
新路径
位置加载图像在我看来,这就是您要存储图像的位置。是否应该从
路径加载图像并将其存储到
新路径
?这是正确的..请告诉我如何操作..我没有任何想法,它会抛出一个filenotfound错误..我的图像文件路径类似于
AiringCupboard0\u 1.jpg/Job\u Files/74/10\u AiringCupboard0/Images/AiringCupboard0\u 1.jpg
,在这种情况下,您可以必须确保,就像我说的,路径是一个文件的正确路径。在
path
m只获取
AiringCupboard0\u 1.jpg
Image.FromFile(path)
将能够找到整个路径??不,在路径中,您需要有完整的路径(文件和文件夹)例如:
/Job\u Files/74/10\u AiringCupboard0/Images/AiringCupboard0\u 1.jpg
如果您有,您可能还需要在将整个
路径
附加到它的末尾时,再次查看构建
新路径的行(您可能只需要文件名)是的,你说得对……这是唯一一个路径错误,因为GDI+中发生了一个一般错误。