【问题标题】:Delete a image, and delete from Image viewer under Win 8删除一张图片,在Win 8下从Image viewer中删除
【发布时间】:2013-07-10 15:58:58
【问题描述】:

我用的是图片,先把图片加载到xaml中的一个图片控件中:

<Image Name="pic" Height="550" Width="400"  Source="{Binding img}"  Stretch="Fill"/>

加载到图像后,我想删除源文件,并从图像控件中删除。

按钮点击:

pic.Source = null;   
StorageFile sf = null;
StorageFolder sd = ApplicationData.Current.LocalFolder;
sf = await sd.GetItemAsync("imgs\\img") as StorageFile;
await sf.DeleteAsync();

但是:拒绝访问。

我用这个:

pic.Source = null;

但同样的问题。我怎样才能删除图像?

感谢所有回复!

【问题讨论】:

  • 您从 XAML 绑定到的 img 属性是什么?
  • 你确定你没有引用另一个控件中的图像吗?
  • 首先,尝试使用SetSource。其次,您可以将可见性设置为折叠吗?关于拒绝访问问题,您可能需要调查在您尝试删除文件时该文件是否仍在使用中。

标签: c# windows-8 microsoft-metro windows-store-apps winrt-xaml


【解决方案1】:

解决办法是:这种格式不可能,但是这样解决了这个问题:

RandomAccessStreamReference rs= RandomAccessStreamReference.CreateFromUri(new Uri(path));
        BitmapImage bi = new BitmapImage();
        var rstream = await rs.OpenReadAsync();
        bitmapImage.SetSource(rstream);
        pic.Source = bi;

图像必须加载到流中,文件才能删除。

【讨论】:

    猜你喜欢
    • 2014-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 1970-01-01
    • 2021-05-04
    相关资源
    最近更新 更多