How can I check if two images have same source in 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. However the most likely implementation is BitmapImage . So you can check of its type and if it is BitmapImage or IUriContext you can cast it and compare the BaseUri property.
您正在比较参考,比较值...
if(image1.source.ToString().Equals(image2.source.ToString())) {}
You can compare both of the images with the help of 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.");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.