Пример #1
0
        //test the number passed into this method against the image. Returns true if the number of bits tested returns a valid message header
        private char Decode(int numBitsUse, EmbedTracker tracker)
        {
            Byte     r, g, b;
            int      numRead  = 0;
            BitArray dataByte = new BitArray(8);

            try
            {
                //try and read for the first character of the start of message which should be at the beginning of the image
                while (numRead < 8)
                {
                    int      processingX = tracker.currX;
                    int      processingY = tracker.currY;
                    var      currPixel   = orgBitmap.GetPixel(processingX, processingY);
                    BitArray currentByte = new BitArray(8);

                    switch (tracker.nxtColorVal)
                    {
                    case 0:
                        currentByte = new BitArray(new byte[] { currPixel.R });
                        break;

                    case 1:
                        currentByte = new BitArray(new byte[] { currPixel.G });
                        break;

                    case 2:
                        currentByte = new BitArray(new byte[] { currPixel.B });
                        break;
                    }
                    //this is not correct might be an encoding issue
                    for (int i = 0; i < numBitsUse; i++)
                    {
                        if (numRead < 8)
                        {
                            dataByte[numRead] = currentByte[i];
                            numRead++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    tracker.incrementNextTarget();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }


            return((char)ConvertToByte(dataByte));
        }
Пример #2
0
        //store the information in the source array into the target array
        private void store(BitArray targetArray, BitArray sourceArray, EmbedTracker tracker, int numUsed)
        {
            //if they select 3 bits to use
            //on the last pass -- would only need to use 2 bits ( 3, 6, 9)
            int numToUse = numBitsUse;

            try
            {
                if ((numUsed + numToUse) > 8)
                {
                    numToUse = ((numToUse + numUsed) % 8) + 1;
                }
                for (int j = 0; j < numToUse; j++)
                {
                    targetArray[j] = sourceArray[numUsed];
                    tracker.incrementNextTarget();
                    numUsed++;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }