简体   繁体   English

如何检查Windows Phone 7和C#中两个图像的来源是否相同?

[英]how to check if sources of two images are same in Windows Phone 7 and C#?

How can I check if two images have same source in wp7 C#? 如何在wp7 C#中检查两个图像是否具有相同的源? I am doing this but it's not working. 我这样做但是没有用。

if(image1.source.tostring()==image2.source.tostring()){}

I can't see any easy way to do that. 我看不到任何简单的方法。 ImageSource is an abstract class and can be anything therefore it is hard to compare. ImageSource是一个抽象类,可以是任何东西,因此很难比较。 However the most likely implementation is BitmapImage . 但最可能的实现是BitmapImage So you can check of its type and if it is BitmapImage or IUriContext you can cast it and compare the BaseUri property. 所以,你可以检查它的类型,如果是的BitmapImage或IUriContext你可以施放它和比较基本URI属性。

您正在比较参考,比较值...

if(image1.source.ToString().Equals(image2.source.ToString())) {}

You can compare both of the images with the help of BitmapImage 您可以在BitmapImage的帮助下比较两个图像

BitmapImage image1= new BitmapImage(new Uri("your first image relative path", UriKind.Relative))

BitmapImage image2= new BitmapImage(new Uri("your second image relative path", UriKind.Relative))

if(image1==image2)
{
MessageBox.show("Image matched.");
}
else
{
MessageBox.Show("Not matched.");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM