gpt4 book ai didi

c# - Bitmap.UriSource 未设置

转载 作者:太空宇宙 更新时间:2023-11-03 10:29:34 25 4
gpt4 key购买 nike

这有效:
Uri 作为参数直接发送到构造函数会设置对象 photoUriSource

BitmapImage photo = new BitmapImage(new Uri("pack://application:,,,/Images/EmptyImage.jpg"));

enter image description here

不起作用:

但是设置 UriSource 属性会使 UriSource 保持为 null

BitmapImage photo = new BitmapImage();
photo.UriSource = new Uri("pack://application:,,,/Images/EmptyImage.jpg");

enter image description here

最佳答案

根据 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com