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 4623662
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:01:16+00:00 2026-05-22T03:01:16+00:00

if a single image has been saved twice with two different filenames, is there

  • 0

if a single image has been saved twice with two different filenames, is there a way to compare them to see if they’re the same..?

I’m hoping a basic hash or CRC type check could work..?

File size might not, as there are millions of images in the pool and different images could have the same size..

Hoping there’s an easy way to do it in C#..

  • 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-05-22T03:01:17+00:00Added an answer on May 22, 2026 at 3:01 am

    If the file contents are identical, then a cryptographic hash would at least give a very good indication of equality. The SHA256 class would be a good candidate here, although it’s possibly a little over the top. For example:

    static byte[] Sha256HashFile(string file)
    {
        using (SHA256 sha256 = SHA256.Create())
        {
            using (Stream input = File.OpenRead(file))
            {
                return sha256.ComputeHash(input);
            }
        }
    }
    

    The simplest way to compare the two returned byte arrays is probably to convert them both to strings using Convert.ToBase64 and then compare the strings. Ugly but easy 🙂 You could also use Enumerable.SequenceEqual:

    byte[] hash1 = Sha256HashFile("file1.png");
    byte[] hash2 = Sha256HashFile("file2.png");
    bool same = hash1.SequenceEqual(hash2);    
    

    If you want to store the hashes as a set or dictionary, you could implement your own IEqualityComparer<byte[]> but frankly it would be easiest to use a base64 string. For example, this will print out the duplicate files:

    var hashToNameMap = new Dictionary<string, string>();
    foreach (string file in files)
    {
        byte[] hash = Sha256HashFile(file);
        string base64 = Convert.ToBase64(hash);
        string existingName;
        if (hashToNameMap.TryGetValue(base64, out existingName))
        {
            Console.WriteLine("{0} is a duplicate of {1}", file, existingName);
        }
        else
        {
            hashToNameMap[base64] = file;
        }
    }
    

    A few notes:

    • This isn’t guaranteed to be accurate, but the chances of getting a collision are very small, particularly if the files also have to be valid images.
    • This involves reading all of every file – even if there are no other files with the same size (and therefore no possible duplicates). This may or may not be an issue for you.
    • Even if there are multiple files of the same size, you only need to read all of them to find duplicates… you could potentially read the files and compute the hashes as you go, stopping as soon as you find that files are different.

    How you approach this depends on whether your goal is absolute speed, simplicity of code, etc. It may also depend on whether the pool will grow over time – for example, you may want to hash files as soon as you get two or more files of the same size, so that when you add another file of the same size you can hash that and add it without ever rereading the existing data.

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

Sidebar

Related Questions

im trying to combine two images into a single image. unfortunately this has to
I'm loading layers of images to make a single image. I'm currently stacking them
Suppose a single image is saved as pdf. How can I get DPI, width
This has probably been asked a lot, and I see a whole bunch of
I have a menu composed of a single image (e.g., sprites). In order to
I built some cross fade rollovers in IE7 using this single image technique: http://jqueryfordesigners.com/image-cross-fade-transition/
I have an image upload page (single page). When submitted it check filesize and
Is there a trick to making 9patch images with single pixel borders? I'm not
i have implemented a code that fetch single image from 1000+ images. The image
I've been considering image hosting services for a project but am starting to wonder

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.