在 WinRT 应用程序中,我有 2 个不同的图像,但来源相同:
<Image Name="image1" Source="mySource.png"/>
<Image Name="image2" Source="mySource.png"/>
当我将 image1.Source 与 image2.Source 进行比较时,它返回 false 。如果显示相同的图片,如何比较源以求真实?
最佳答案
您必须将Source
对象转换为位图。然后您可以比较 AbsoluteUri
:
BitmapImage bm1 = (BitmapImage)image1.Source;
BitmapImage bm2 = (BitmapImage)image2.Source;
bool same =
(string.Compare(bm1.UriSource.AbsoluteUri, bm2.UriSource.AbsoluteUri) == 0);
关于windows-8 - 比较 Image.Source,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15721393/