- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这有效:
将 Uri
作为参数直接发送到构造函数会设置对象 photo
的 UriSource
。
BitmapImage photo = new BitmapImage(new Uri("pack://application:,,,/Images/EmptyImage.jpg"));
不起作用:
但是设置 UriSource
属性会使 UriSource
保持为 null
BitmapImage photo = new BitmapImage();
photo.UriSource = new Uri("pack://application:,,,/Images/EmptyImage.jpg");
最佳答案
根据 MSDN
BitmapImage.UriSource must be in a BeginInit/EndInit block.
所以你需要这样设置:
BitmapImage photo = new BitmapImage();
photo.BeginInit();
photo.UriSource = new Uri("pack://application:,,,/Images/EmptyImage.jpg");
photo.EndInit();
关于c# - Bitmap.UriSource 未设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30726890/
这有效: 将 Uri 作为参数直接发送到构造函数会设置对象 photo 的 UriSource。 BitmapImage photo = new BitmapImage(new Uri("pack:/
我需要从 UriSrouce 创建一个 BitmaImage 并打印它(在 WPF 应用程序中)。使用以下代码我可以打印图像: Image imgVoucher = new Image(); Bitm
我正在尝试将自定义对象列表绑定(bind)到 WPF 图像,如下所示: 但是这不起作用。这是我收到的错误: “必须设置属性“UriSource”或属性“Str
我正在使用 BitmapImage 类在 WPF 中加载图像。当我为 UriSource 提供绝对路径时,我的代码工作得很好,但当我尝试使用相对路径时却没有。 我的 XAML 是:
我正在尝试构建一个基于 Image 的自定义控件,它只是使图像在计时器上重新加载(从相同的 URI)。原始图像显示正常,但似乎没有刷新。 这里是自定义控件: public class RefreshI
我是一个 WPF 和 Xaml-noob,对于控制台应用程序,它对我来说只是简单地提供可执行文件的相对路径来访问文件。 对我来说,它似乎不适用于 xaml。 (代码在底部) 绝对路径完美运行。 是否可
我目前正在为数据绑定(bind) WPF 图像工作: 足够简单。 现在,向该图像添加缓存(我希望能够在加载本地文件后对其进行操作/删除)。我发现您可以将 CacheOption="OnLoad"添加
我试图通过隐藏代码设置 wpf 图像类的源属性,但由于未知原因它无法正常工作。 我的代码是这样的 1 BitmapImage img = new BitmapImage(); 2 img.UriS
我在 WPF 用户控件中显示带有 Web URL 的图像时遇到问题。对于 2008 年 8 月在本网站上提出的类似问题,我已经完成了所有建议 (Image UriSource and Data Bin
我是一名优秀的程序员,十分优秀!