Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8469507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:14:52+00:00 2026-06-10T16:14:52+00:00

I’ve red a few posts regarding image comparison, and I tried to save image

  • 0

I’ve red a few posts regarding image comparison, and I tried to save image captured from screen then store it in file system .

I used conversion methods to convert captured image into byte[] for later use .

Then when I want to compare it to second screen capture, I load (file saved into byte[]) and compare it against new capture that converted into byte[] in the same way.

Now when having both 1st capture and 2nd capture, in memory, there was few ways to do the comparison, I wanted firstly to share this post with others searching for the same answer and for me to know :

Which is faster, and how do I control the percentage of the similarity?

If the option to have percentage (of equality) is opposing the fastest way to compute…
I can disregard it, although I could use it in other projects when performance issue is not there, and according to its needs

These are the codes I know available to do the task

I wanted to check with you for ideas which is faster and if there’s a better way at all with and without equality percentage. Thank you.

static bool ByteArrayCompare(byte[] a1, byte[] a2)
{     
  IStructuralEquatable eqa1 = a1;     
  return eqa1.Equals(a2, StructuralComparisons.StructuralEqualityComparer); 
} 

vs

public enum CompareResult
{
  ciCompareOk,
  ciPixelMismatch,
  ciSizeMismatch
};

CompareResult cr = CompareResult.ciCompareOk;

byte[] hash1 = shaM.ComputeHash(btImage1);
byte[] hash2 = shaM.ComputeHash(btImage2);

//Compare the hash values
for (int i = 0; i < hash1.Length && i < hash2.Length 
                  && cr == CompareResult.ciCompareOk; i++)
{
    if (hash1[i] != hash2[i])
        cr = CompareResult.ciPixelMismatch;
}

the later is using System.Security.Cryptography

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:14:54+00:00Added an answer on June 10, 2026 at 4:14 pm

    Comparing images and comparing byte arrays/file content are 2 different tasks as image format may wary. So assuming you are interested in byte comparison (i.e. if the same code used to capture images results should be the same). Otherwise you need to search for “compare images” questions (like one How to compare Image objects with C# .NET? suggested by Jensen Somers).

    To compare byte arrays/files you will eventually need to compare byte content byte by byte. You can optimize checks to do nothing for cases when byte arrays/files will definitely not match and do byte compare only when strictly necessary:

    • check if sizes are the same
    • check hashes of arrays/files (cache computed hash values, since computing hash every time will not be any faster than byte-by-byte comparison). SHAxxxx hashes are good, but any reasonable hash function even several randomly taken bytes of arrays would do. With just picking values from array you may avoid caching hashes altogether.
    • compare fixed size chunk of arrays (i.e. somewhere in the middle for images) if you expect files to be different more often than the same.

    If above says arrays/files could be the same (same length/hash/partial content) than compare arrays/files byte-by-byte.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.