R
R
Rasse2020-12-21 10:41:52
C++ / C#
Rasse, 2020-12-21 10:41:52

Why does this code produce a different image hash on different machines?

//cropped -тут приходит обрезанное изображение
            var cropped = CropImage(scr, new Rectangle(436, 986, 23, 26));
            string ss = "";
            if (cropped != null)
            {
                int width = cropped.Width;
                int height = cropped.Height;
                decimal aspectRatio = width > height ? decimal.Divide(width, height) : decimal.Divide(height, width);
                using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
                {
                    cropped.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

                    Byte[] imageBytes = stream.GetBuffer();
                    System.Security.Cryptography.MD5CryptoServiceProvider provider = new System.Security.Cryptography.MD5CryptoServiceProvider();
                    Byte[] hash = provider.ComputeHash(imageBytes);

                    System.Text.StringBuilder hashBuilder = new System.Text.StringBuilder();

                    for (int i = 0; i < hash.Length; i++)
                    {
                        hashBuilder.Append(hash[i].ToString("X2"));
                    }

                    ss = hashBuilder.ToString();
                    stream.Dispose();
                }


                cropped.Dispose();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-12-21
@firedragon

Binary comparison online
https://www.diffnow.com/compare-files
// it's probably better to save it this way.
cropped.Save(stream, System.Drawing.Imaging.ImageFormat.Png);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question