Пример #1
0
        /// <summary>
        /// Return the hash of the specified file, calculated using the specified hash algorithm.
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static ImageHash HashImage(HashAlgorithm algorithm, string filePath)
        {
            ImageHash hash;

            switch (algorithm)
            {
            case HashAlgorithm.DCT:
                ulong DCTHash;
                NativeFunctions.ph_dct_imagehash(filePath, out DCTHash);
                hash = new DCTHash(DCTHash);
                break;

            case HashAlgorithm.Radial:
                NativeStructures.Digest digest;
                NativeFunctions.ph_image_digest(filePath, 1, 1, out digest);
                hash = new RadialHash(digest);
                break;

            case HashAlgorithm.MH:
                int    count;
                IntPtr hashBytes = NativeFunctions.ph_mh_imagehash(filePath, out count);
                hash = new MHHash(hashBytes, count);
                break;

            default:
                throw new NotImplementedException();
            }
            return(hash);
        }
Пример #2
0
 /// <summary>
 /// Return the hash of the specified file, calculated using the specified hash algorithm.
 /// </summary>
 /// <param name="algorithm"></param>
 /// <param name="filePath"></param>
 /// <returns></returns>
 public static ImageHash HashImage(HashAlgorithm algorithm, string filePath)
 {
     ImageHash hash;
     switch (algorithm)
     {
         case HashAlgorithm.DCT:
             ulong DCTHash;
             NativeFunctions.ph_dct_imagehash(filePath, out DCTHash);
             hash = new DCTHash(DCTHash);
             break;
         case HashAlgorithm.Radial:
             NativeStructures.Digest digest;
             NativeFunctions.ph_image_digest(filePath, 1, 1, out digest);
             hash = new RadialHash(digest);
             break;
         case HashAlgorithm.MH:
             int count;
             IntPtr hashBytes = NativeFunctions.ph_mh_imagehash(filePath, out count);
             hash = new MHHash(hashBytes, count);
             break;
         default:
             throw new NotImplementedException();
     }
     return hash;
 }