C# 根据名称将位图图像保存在子ImageFolder中

C# 根据名称将位图图像保存在子ImageFolder中,c#,bitmap,save,jpeg,store,C#,Bitmap,Save,Jpeg,Store,在我的代码中,我创建了一个图像文件夹,在图像文件夹中,我再次创建了一个子文件夹。我已经从url下载了一个静态谷歌地图图像。我想根据位置名称将其保存在子文件夹中。但它不会保存在它保存在图像文件夹中的子文件夹中。它还会在图像名称前面显示位置名称。但我只需要散列码。不是文件名。这是我用来下载和存储图像的代码 public static void Map(string LocationName) { using (WebClient wc = new WebClient()) {

在我的代码中,我创建了一个图像文件夹,在图像文件夹中,我再次创建了一个子文件夹。我已经从url下载了一个静态谷歌地图图像。我想根据位置名称将其保存在子文件夹中。但它不会保存在它保存在图像文件夹中的子文件夹中。它还会在图像名称前面显示位置名称。但我只需要散列码。不是文件名。这是我用来下载和存储图像的代码

public static void Map(string LocationName)
{
    using (WebClient wc = new WebClient())
    {

        var client = new WebClient();

        var startPath = Application.StartupPath;
        string Imagefolder = Path.Combine(startPath, "Image");
        string subImageFolder = Path.Combine(Imagefolder, LocationName);
        System.IO.Directory.CreateDirectory(subImageFolder);
        string Jpeg = Path.Combine(Environment.CurrentDirectory, subImageFolder);

        var uri = ("http://maps.googleapis.com/maps/api/staticmap?center=" + LocationName + "&zoom=9&size=300x200&maptype=roadmap&markers=color:blue%7Clabel:S&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284&sensor=false");
        HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(uri);

        HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse();
        Stream imageStream = httpResponse.GetResponseStream();
        Bitmap buddyIcon = new Bitmap(imageStream);
        httpResponse.Close();
        imageStream.Close();
        Image2.SizeMode = PictureBoxSizeMode.StretchImage;

        //Load Image
        Image2.Image = buddyIcon;
        var hash = uri.GetHashCode();
        buddyIcon.Save(Jpeg + hash.ToString("X") + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
    }
}

Save(Path.combine(jpeg,hash.ToString(“X”)+”.jpg),System.Drawing.Imaging.ImageFormat.jpeg);你能试试吗?我现在没有电脑来测试你的代码。非常感谢。它解决了这个问题@西蒙威尔逊