예제 #1
0
        /// <summary>
        /// Calculates the perceptual hash of the first content image of the book and writes it to a file
        /// The perceptual hash may very well take on the value null. If so, the file will contain the literal string "null" (without the quotes) in it.
        /// </summary>
        /// <param name="parameters">parameters.PHashOutputInfoPath should contain the file path to which the create/write the PHash</param>
        public static void CreatePHashArtifact(CreateArtifactsParameters parameters)
        {
            if (String.IsNullOrWhiteSpace(parameters.PHashOutputInfoPath))
            {
                return;
            }

            // This could take a second or more.
            string pHash = _book.ComputePHashOfFirstContentImage();

            using (var writer = new StreamWriter(parameters.PHashOutputInfoPath, append: false))
            {
                // Do note that the pHash may be null and it is expected that some books will legitimately have a null pHash
                // so we write this value explicitly so that consumers can explicitly detect this.
                writer.WriteLine(pHash ?? "null");
            }
        }