예제 #1
0
 public void TestComputeHash()
 {
     using (var imageStream = TestImage.Flora.GetStream())
         using (var bmp = (Bitmap)Image.FromStream(imageStream))
         {
             var hash = BitmapHash.Compute(bmp);
             Assert.NotNull(hash);
         }
 }
예제 #2
0
        public void TestCompareCompressedPicture()
        {
            using (var imageStream1 = TestImage.Flora.GetStream())
                using (var bmp1 = (Bitmap)Image.FromStream(imageStream1))
                    using (var imageStream2 = TestImage.FloraCompressed.GetStream())
                        using (var bmp2 = (Bitmap)Image.FromStream(imageStream2))
                        {
                            var hash1 = BitmapHash.Compute(bmp1);
                            var hash2 = BitmapHash.Compute(bmp2);

                            var diff = BinaryUtils.ComputeByteArrayEquality(hash1, hash2);
                            Assert.True(diff > 0.9);
                        }
        }
예제 #3
0
        public FileInformation Load(IFile file, Stream stream)
        {
            _logger.LogDebug("Load file information of {filename}", file.Filename);

            PhotoProperties?properties;
            Hash            fileHash;
            DateTimeOffset  fileCreatedOn;

            fileCreatedOn = GetCreationDate(stream, file);

            stream.Position = 0;
            try
            {
                using var bmp = new Bitmap(stream);

                var width   = bmp.Width;
                var height  = bmp.Height;
                var bmpHash = new Hash(BitmapHash.Compute(bmp));

                properties = new PhotoProperties(bmpHash, width, height);
            }
            catch (Exception)
            {
                properties = null;
            }

            stream.Position = 0;
            fileHash        = _fileHasher.ComputeHash(stream);

            var fileInformation = new FileInformation(file.Filename, file.CreatedOn, file.ModifiedOn, fileHash, file.Length,
                                                      fileCreatedOn, properties, file.RelativeFilename);

            _logger.LogDebug("FileInformation of file {filename} loaded: {@data}", file.Filename, fileInformation);

            return(fileInformation);
        }