图像文件加载锁定在WPF后图像文件、加载、WPF

2023-09-03 06:26:53 作者:沵湜莪嘸琺企及的光

我读我的WPF的ImageSource是这样的:

I am reading my WPF imagesource like this:

dim bmi as new bitmapimage()
bmi.begininit()
bmi.cachoption = None
bmi.UriSource = new Uri(MyFileName, Urikind.Absolute)
bmi.endedit

它的工作原理像它应该到了这一点。 但是用户可以通过复制文件更新图像。 然后,我要刷新的图像。但文件MyFileName的被锁定,当我想要做覆盖它,它抛出一个错误,这是已经在使用并锁定。

It works like it should until this point. But user can update the image by copying the file. Then I want to refresh the image. But the file "MyFileName" is locked and when I want do overwrite it, it throws an error that it is already in use and locked.

别急,我在这里寻找一个解决方案,我知道了:

But wait, I searched here for a solution and I got it:

bmi.cachoption = OnLoad

是关键... BUT!现在,图像总是旧,并且不更新为新的文件。 如何清除这个缓存?

was the key... BUT!! now, the image is always the old one and is not updated to the new file. How to clear this cache?

在VB.Net我从流中System.Drawing.Bitmap。如何做到这一点最好的办法在WPF?

In VB.Net I made an System.Drawing.Bitmap from stream. How to do it best way in WPF?

问候

推荐答案

dlev有一个很好的建议。这里你可以看到缓存选项来解决这个问题:WPF - 覆盖问题(重新保存)图像时它被设定为图像源

dlev had a good advice. Here you see the cache option to solve it: WPF - Problems overwriting (re-saving) image when it was set as image source

imgTemp.CreateOption = BitmapCreateOptions.IgnoreImageCache
 
精彩推荐
图片推荐