C# 正在将BitmapImage强制转换为Image.Source
我目前正在Visual Studio 2017中完成一个项目。下面的代码旨在设置.xaml页面上图像组件的源代码C# 正在将BitmapImage强制转换为Image.Source,c#,image,xaml,url,bitmapimage,C#,Image,Xaml,Url,Bitmapimage,我目前正在Visual Studio 2017中完成一个项目。下面的代码旨在设置.xaml页面上图像组件的源代码 private void setImage() { var image = new Image(); var imageUrl = @"http://ddragon.leagueoflegends.com/cdn/5.2.1/img/" + currentChamp.Image.Group + "/" + currentCham
private void setImage()
{
var image = new Image();
var imageUrl = @"http://ddragon.leagueoflegends.com/cdn/5.2.1/img/" +
currentChamp.Image.Group + "/" + currentChamp.Image.Full;
Debug.Write(imageUrl);
BitmapImage bmi = new BitmapImage();
bmi.BeginInit();
bmi.UriSource = new Uri(imageUrl, UriKind.Absolute);
bmi.EndInit();
image.Source = bmi;
}
下面是要引用的代码^^^
在我发现的所有其他问题中,与我所问的问题类似,这是我试图做的事情的正确/回答/认可的方式。但是,我收到了一个错误,其他人在任何问题中都没有收到该错误
无法将system.windows.media.imaging.BitmapImage隐式转换为windows.UI.XAML.media.ImageSource
我的导入、引用和类型都已检查,并且都是正确的。我是否缺少一个框架?是否有可能导致此功能不再工作的更新
我使用的是在Microsoft.NETCore.UniversalWindowsPlatform中工作的VS2017
请注意,这不是的副本,因为我没有引用资源文件夹,并且我的路径是绝对路径。此处的错误消息会准确地告诉您错误所在。您正在UWP项目中使用非UWP
位图图像。摆脱对System.Windows.Media.Imaging
的使用,并将其更改为Windows.UI.Xaml.Media.Imaging
此处的错误消息会准确地告诉您出了什么问题。您正在UWP项目中使用非UWP位图图像。摆脱对System.Windows.Media.Imaging
的使用,将其更改为Windows.UI.Xaml.Media.Imaging
Windows.Media.Imaging.BitmapImage
是一个WPF类Windows.UI.XAML.media.ImageSource
是UWP。您找到了WPF的解决方案,但您的UWPImage
类需要一个UWP位图对象。你需要一些有用的东西
目前我无法测试UWP,但通过阅读文档,我认为您需要以下内容:
image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(imageUrl, UriKind.Absolute));
您似乎已使用Windows.Media.Imaging代码>在您的C#文件中。明智的做法是使用Windows.UI.Xaml.Media.Imaging将其替换为代码>
那么你可以用这个:
image.Source = new BitmapImage(new Uri(imageUrl, UriKind.Absolute));
Windows.Media.Imaging.BitmapImage
是一个WPF类Windows.UI.XAML.media.ImageSource
是UWP。您找到了WPF的解决方案,但您的UWPImage
类需要一个UWP位图对象。你需要一些有用的东西
目前我无法测试UWP,但通过阅读文档,我认为您需要以下内容:
image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(imageUrl, UriKind.Absolute));
您似乎已使用Windows.Media.Imaging代码>在您的C#文件中。明智的做法是使用Windows.UI.Xaml.Media.Imaging将其替换为代码>
那么你可以用这个:
image.Source = new BitmapImage(new Uri(imageUrl, UriKind.Absolute));
就像你的例子一样,这非常有效。非常感谢你,我永远也听不到。我对c#比较陌生,调试一直是我最大的挑战。这非常有效,就像你的例子一样。非常感谢你,我永远也听不到。我对c#比较陌生,调试一直是我最大的挑战。