删除存储文件(图像) C# 地铁应用
本文关键字:地铁 应用 图像 存储文件 删除 | 更新日期: 2023-09-27 18:37:28
我有一个问题,在我的应用程序中使用或显示保存在我的应用程序的本地文件夹中的 Gridview 中的图像,我想通过选择它们来删除这些图像,但问题是这些图像正在使用中,当任何内容(文件或图像)打开或使用时,它们都在 Windows 中,因此不应从驱动器中删除。 我想从硬盘中删除图像。 m 使用或访问这些GridView 中的图像通过 BitmapImage 中的 URI 路径。喜欢这个
私有图像源 _image = 空;this._image = new BitmapImage(new Uri(new Uri("ms-appdata:///local/RecentImages/"), this._imagePath));
和我试图删除请告诉我如何停止或处理 GridView 和存储文件之间的此链接或如何从存储设备中删除图像?
我假设没有其他应用程序同时加载相同的图像。这是一种在将图像文件流加载到内存中后关闭图像文件流的方法。
/// <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;
}