Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 删除存储文件(图像)C metro应用程序_C#_Windows 8_Microsoft Metro - Fatal编程技术网

C# 删除存储文件(图像)C metro应用程序

C# 删除存储文件(图像)C metro应用程序,c#,windows-8,microsoft-metro,C#,Windows 8,Microsoft Metro,我有一个问题,在我的应用程序中,我正在使用或在Gridview中显示保存在我应用程序本地文件夹中的图像,我想通过选择这些图像来删除这些图像,但问题是,当打开或使用任何文件或图像时,这些图像正在使用,并且在windows中,所以不应从驱动器中删除。我想从硬盘上删除图像。我正在使用或通过BitmapImage中的URI路径访问GridView中的这些图像。像这样 私有ImageSource _image=null; 此。_image=new-BitmapImagenew-Urims-appdata:

我有一个问题,在我的应用程序中,我正在使用或在Gridview中显示保存在我应用程序本地文件夹中的图像,我想通过选择这些图像来删除这些图像,但问题是,当打开或使用任何文件或图像时,这些图像正在使用,并且在windows中,所以不应从驱动器中删除。我想从硬盘上删除图像。我正在使用或通过BitmapImage中的URI路径访问GridView中的这些图像。像这样

私有ImageSource _image=null; 此。_image=new-BitmapImagenew-Urims-appdata:///local/RecentImages/,这个。_imagePath

我正试图删除 请告诉我如何停止或处理GridView和StorageFile之间的链接
或者如何从存储设备中删除图像???

我假设没有其他应用程序同时加载相同的图像。 下面是一种在将图像文件流加载到内存后关闭图像文件流的方法

    /// <summary>
    /// Gets the bitmap.
    /// </summary>
    /// <param name="path">The path.</param>
    /// <returns></returns>
    public static BitmapSource GetBitmap(string path)
    {
        if (!File.Exists(path)) return null;

        MemoryStream ms = new MemoryStream();
        BitmapImage bi = new BitmapImage();
        byte[] bytArray = File.ReadAllBytes(path);
        ms.Write(bytArray, 0, bytArray.Length); ms.Position = 0;
        bi.BeginInit();
        bi.StreamSource = ms;
        bi.EndInit();
        return bi;
    }

打开图像时,在读取图像数据后,关闭图像文件流。如何关闭图像流sir?这些图像在我的Gridview中用作最近的活动,每次在我的主页上打开时,我都会使用URI路径获取这些图像,而不是我的流sir。请检查下面的代码。我不确定以下内容是否能稳定地与metro配合使用,但它解决了我的问题。