Esempio n. 1
0
 public void Validate(EncodeRequest request)
 {
     ValidateNotNull(request, "Request must not be null");
     ValidateCoverImage(request.CoverPath);
     ValidateMessage(request.MessagePath);
     ValidateMessageSize(request);
     ValidateResultPath(request.ResultPath);
 }
Esempio n. 2
0
        private void ValidateMessageSize(EncodeRequest request)
        {
            FileInfo messageInfo = new FileInfo(request.MessagePath);
            Bitmap   image       = (Bitmap)Image.FromFile(request.CoverPath);
            int      pixelCount  = image.Width * image.Height;
            int      freeBits    = pixelCount * 3;
            int      headerBits  = new BitArray(BitConverter.GetBytes(freeBits)).Count;

            if (freeBits - headerBits < messageInfo.Length)
            {
                throw new ValidationException("Message size is greater the the free bytes in cover image");
            }
        }
Esempio n. 3
0
        public void EncodeMessageSeq(EncodeRequest request)
        {
            encodeValidator.Validate(request);
            Bitmap     coverImage        = new Bitmap(request.CoverPath);
            Rectangle  rect              = new Rectangle(0, 0, coverImage.Width, coverImage.Height);
            BitmapData coverData         = coverImage.LockBits(rect, ImageLockMode.ReadWrite, coverImage.PixelFormat);
            IntPtr     ptr               = coverData.Scan0;
            int        bytes             = Math.Abs(coverData.Stride) * coverImage.Height;
            BitArray   messageWithHeader = CreateMessageWithHeader(bytes, request.MessagePath);

            EncodeMessageIntoCoverSeq(messageWithHeader, bytes, ptr);
            coverImage.UnlockBits(coverData);
            coverImage.Save(request.ResultPath);
        }