There is several methods, for example:
1. Keypoint Matching
2. Histogram method
3. Keypoints + Decision Trees
4. file-hash based (md5,sha1,etc) for exact duplicates
5. perceptual hashing (phash) for rescaled images
6. feature-based (SIFT) for modified images
For further details, please see:
Image comparison - fast algorithm[
^]
It depends on what you mean by "compare two images"...
For starters, i'd suggest to read this excellent CP's article:
Simple image comparison in .NET[
^]