刷新画布中的图像 [英] Refreshing images in Canvas

查看:589
本文介绍了刷新画布中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个显示图像的画布.这些图像应该在运行时更新.当图像已经显示并且正在显示qeue中的下一个图像时,将进行更新.但是,由于出现文件正在被另一个进程使用"异常,因此我无法删除或修改以前显示的图像.似乎Canvas仍然可以控制以前显示的文件.我尝试了canvas.children.clear(),但没有帮助.有谁知道如何删除该链接(关闭文件或...)?

Hello All

I have a canvas that displays images. These images supposed to be updated at run time. Update happens when the image is already display and the next image in the qeue is being displayed. However I am not able to delete nor modify the previously displayed images since I get the "file is being used by another process" exception. It seems like Canvas still has its grip on the previously displayed files. I tried canvas.children.clear() but it didn''t help. Does anyone one know how to remove that link (close file or...)?

 Uri newUri = new Uri(@inputA);
 Image.ImageSource = new BitmapImage(newUri);

ImageCanvas.Children.Clear();  // this didnt help

推荐答案

hi
您的应用程序本身拥有该文件,因此我们需要使用文件流等,如下所示

hi
your application itself holding that file so we need to use filestream etc like below

FileInfo fileinfo = new FileInfo(filepath);
  if (fileinfo.Exists)
   {
      using (FileStream fs = System.IO.File.Open(filepath,
                                                  FileMode.Open,
                                                  FileAccess.Read,
                                                  FileShare.ReadWrite))
       {
          using (StreamReader reader = new StreamReader(fs))
           {  
              BitmapImage bitImg = new BitmapImage()
              bitImg.StreamSource=reader ;
              Image.ImageSource= bitImg; 
             }
        }
   }


问候
西拉子(Siraz)


Regards
Siraz


这篇关于刷新画布中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆