Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从web加载图像时出现NullReferenceException BitmapImage bi=新的BitmapImage(新Uri)(https://www.google.com/images/srpr/logo11w.png乌里金(绝对值); myImage.Source=bi;_C#_Image_Visual Studio_Windows Phone 8_Windows Phone - Fatal编程技术网

C# 从web加载图像时出现NullReferenceException BitmapImage bi=新的BitmapImage(新Uri)(https://www.google.com/images/srpr/logo11w.png乌里金(绝对值); myImage.Source=bi;

C# 从web加载图像时出现NullReferenceException BitmapImage bi=新的BitmapImage(新Uri)(https://www.google.com/images/srpr/logo11w.png乌里金(绝对值); myImage.Source=bi;,c#,image,visual-studio,windows-phone-8,windows-phone,C#,Image,Visual Studio,Windows Phone 8,Windows Phone,这是我的密码。没有困难,没有复杂。但是,它在“myImage.Source=bi”处给了我一个NullReferenceException。怎么了 <Image Name="myImage" Width="160" Height="226"/> BitmapImage bi = new BitmapImage(new Uri(https://www.google.com/images/srpr/logo11w.png, UriKind.Absolute)); myImage.Sour

这是我的密码。没有困难,没有复杂。但是,它在“myImage.Source=bi”处给了我一个NullReferenceException。怎么了

<Image Name="myImage" Width="160" Height="226"/>
BitmapImage bi = new BitmapImage(new Uri(https://www.google.com/images/srpr/logo11w.png, UriKind.Absolute));
myImage.Source = bi;

这很有效。我做了测试。顺便说一下,找不到“”

什么是我的图像?您确定它不是
null
?myImage很可能在此上下文中尚未实例化。我必须承认,我怀疑您的代码是错误的,或者这是我一点都不熟悉的某种语法。您何时设置
myImage
的源代码?如果它位于页面构造函数中,请确保它位于调用
InitializeComponents
Its之后,而不在页面构造函数中。它在页面的已加载事件中。在InitializeComponent()之后粘贴这些行;然后再试一次。问题不在于@KooKiz提到的这些代码行。即使我将这些代码行粘贴到页面构造函数中,它也不能解决我的问题。如果我想在用户单击按钮时加载图像,该怎么办?@user1924391如果将其放入按钮事件中,该解决方案将非常有效。也许你的xaml有问题。为我工作。。相同的代码。。通过单击按钮加载图像。。我想如果你也粘贴错误的话会有帮助。。
BitmapImage bi = new BitmapImage(new Uri("https://www.google.com/images/srpr/logo11w.png", UriKind.Absolute));

myImage.Source = bi;