/// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Internal constructor that builds the object from bytes
        /// </summary>
        /// <param name="img">the image in which to embed</param>
        /// <param name="planes">the planes to embed in</param>
        /// <param name="bitDepth">the bit depth of the embedding</param>
        /// <returns>the embedding header</returns>
        internal EmbeddingHeader(Bitmap img, EmbeddingPlane planes, int bitDepth)
        {
            try
            {
                // get header
                byte[]   headerBytes = SteganographyMethods.ExtractBytes(img, planes, bitDepth, MAX_HEADER);
                String   header      = System.Text.Encoding.ASCII.GetString(headerBytes).Trim();
                String[] split       = header.Split(new char[1] {
                    HEADER_SPLIT_CHAR
                });

                // set attributes
                this.TypeOfContent = (ContentType)Enum.Parse(typeof(ContentType), split[0].Trim());
                this.SizeOfContent = Convert.ToInt32(split[1].Trim());
                this.Filename      = split[2].Trim();
            }
            catch (Exception e)
            {
                throw new SteganographyException(e.ToString());
            }
        }