【发布时间】:2024-01-13 11:34:01
【问题描述】:
大家好,
我在图像权限方面遇到了一些问题。
我正在从文件加载图像,调整其大小,然后将其保存到另一个文件夹。 然后我这样显示:
uriSource = new Uri(Combine(imagesDirectoryTemp, generatedFileName), UriKind.Absolute);
imgAsset.Source = new BitmapImage(uriSource);
这工作正常,如果用户随后立即选择另一个图像并尝试将其保存在原始文件之上,则会出现问题。
保存我的图片时出现异常"ExternalException: A generic error occurred in GDI+."
经过一番尝试,我将错误缩小到imgAsset.Source = new BitmapImage(uriSource);,因为删除此行而不设置图像源将允许我多次覆盖此文件。
我还尝试将源设置为其他内容,然后重新保存以希望旧的引用会被处理掉,但事实并非如此。
我怎样才能克服这个错误?
谢谢, 可汗
编辑
现在使用此代码我没有收到异常,但是图像源没有更新。另外,由于我没有使用 SourceStream,我不确定我需要处理什么才能使其正常工作。
uriSource = new Uri(Combine(imagesDirectoryTemp, generatedFileName), UriKind.Absolute);
imgTemp = new BitmapImage();
imgTemp.BeginInit();
imgTemp.CacheOption = BitmapCacheOption.OnLoad;
imgTemp.UriSource = uriSource;
imgTemp.EndInit();
imgAsset.Source = imgTemp;
【问题讨论】: