Example #1
0
        /// <summary>
        /// Combines a header and a byte array of content
        /// </summary>
        /// <param name="eh">header</param>
        /// <param name="content">content</param>
        /// <returns>merged byte array</returns>
        private static byte[] MergeHeaderAndContent(EmbeddingHeader header, byte[] content)
        {
            List <byte> retVal = new List <byte>(header.ToByteArray());

            retVal.AddRange(content);
            return(retVal.ToArray <byte>());
        }
        /// <summary>
        /// Extracts the content from the image
        /// </summary>
        /// <param name="img">the image from which to extract</param>
        /// <param name="planes">the planes to embed in</param>
        /// <param name="bitDepth">the bit depth of the embedding</param>
        /// <returns>the embedded content, null if a problem occurs</returns>
        public static EmbeddingContent Extract(Bitmap img, EmbeddingPlane planes, int bitDepth)
        {
            // short circuit
            if ((img == null) || (bitDepth < 1) || (bitDepth > 8))
            {
                return(null);
            }

            // var declatation
            EmbeddingContent retVal = null;

            try
            {
                // get the header to determine what to extract
                EmbeddingHeader eh = new EmbeddingHeader(img, planes, bitDepth);

                // read the bytes
                int totalBytesToExtract = eh.ToString().Length + eh.SizeOfContent;
                retVal = new EmbeddingContent(SteganographyMethods.ExtractBytes(img, planes, bitDepth, totalBytesToExtract));
            }
            catch
            {
                retVal = null;
            }

            return(retVal);
        }