将旋转图像保存到服务器上

Save rotate image onto server

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

图片路径在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);
}

尽管您必须确保变量 pathnew_path 包含图像的完整路径 + 文件名。

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