2

In WinRT app I have 2 different images but with the same source:

 <Image Name="image1" Source="mySource.png"/>
 <Image Name="image2" Source="mySource.png"/>

When I compare image1.Source with image2.Source it returns false . How to compare Sources so as to get true if they show the same picture?

4

1 回答 1

2

You have to cast the Source objects as bitmaps. Then you can compare the AbsoluteUri:

BitmapImage bm1 = (BitmapImage)image1.Source;
BitmapImage bm2 = (BitmapImage)image2.Source;

bool same = 
    (string.Compare(bm1.UriSource.AbsoluteUri, bm2.UriSource.AbsoluteUri) == 0);
于 2013-03-30T23:56:29.717 回答