コード例 #1
0
        private void SetConfPixel(int x, byte val)
        {
            var test1 = WriteReadData.WriteData(_lockBitmap.GetPixel(x, 0), val, null, null, null);

            _lockBitmap.SetPixel(x, 0, WriteReadData.WriteData(_lockBitmap.GetPixel(x, 0), val, null, null, null));
            var test2 = _lockBitmap.GetPixel(x, 0);
        }
コード例 #2
0
        public Bitmap Encrypt(T_Data data)
        {
            if (ImageModifying == null)
            {
                throw new ArgumentException("Parameter cannot be null", "Image");
            }
            if (DataReader == null)
            {
                throw new ArgumentException("Parameter cannot be null", "DataReader");
            }
            if (WriteReadData == null)
            {
                throw new ArgumentException("Parameter cannot be null", "WriteReadData");
            }
            _lockBitmap = new LockBitmap(ImageModifying);
            _lockBitmap.LockBits();

            var dataToEncrypt = DataReader.ToBytes(data);

            WriteReadData.SetSettingsMode();
            // write config ID of module name for Write/Read data in pixel
            //_lockBitmap.SetPixel(WriteReadDataIdPosition, 0,
            //    WriteReadData.WriteData(_lockBitmap.GetPixel(WriteReadDataIdPosition, 0), WriteReadData.GetID(), null, null, null));
            SetConfPixel(WriteReadDataIdPosition, WriteReadData.GetID());
            if (DataCompression != null)
            {
                dataToEncrypt = DataCompression.Compression(dataToEncrypt);
                // write config ID of module Compression
                //_lockBitmap.SetPixel(DataCompressionIdPosition, 0, WriteReadData.WriteData(_lockBitmap.GetPixel(DataCompressionIdPosition, 0), DataCompression.GetID(), null, null, null));
                SetConfPixel(DataCompressionIdPosition, DataCompression.GetID());
            }
            else
            {
                //_lockBitmap.SetPixel(DataCompressionIdPosition, 0, WriteReadData.WriteData(_lockBitmap.GetPixel(DataCompressionIdPosition, 0), 0b00000000, null, null, null));
                SetConfPixel(DataCompressionIdPosition, 0b00000000);
            }

            //_lockBitmap.SetPixel(Encrypt1IdPosition, 0, WriteReadData.WriteData(_lockBitmap.GetPixel(Encrypt1IdPosition, 0), 0b00000000, null, null, null));
            //_lockBitmap.SetPixel(Encrypt2IdPosition, 0, WriteReadData.WriteData(_lockBitmap.GetPixel(Encrypt2IdPosition, 0), 0b00000000, null, null, null));
            SetConfPixel(Encrypt1IdPosition, 0b00000000);
            SetConfPixel(Encrypt2IdPosition, 0b00000000);
            if (Encrypts != null && Encrypts.Count > 0)
            {
                var i = 0;
                foreach (var enc in Encrypts)
                {
                    dataToEncrypt = enc.Encrypt(dataToEncrypt);
                    SetConfPixel(Encrypt1IdPosition + i, enc.GetID());
                    //_lockBitmap.SetPixel(Encrypt1IdPosition + i, 0, WriteReadData.WriteData(_lockBitmap.GetPixel(Encrypt1IdPosition + i, 0), enc.GetID(), null, null, null));

                    if (++i > 1)
                    {
                        break;
                    }
                }
            }

            #region Write configs into image on Alpha path of color

            var dataLengthInBits = dataToEncrypt.Length * 8;
            var toWriteLength = _byteOperations.SplitSettingsBytes(new BitArray(BitConverter.GetBytes(dataLengthInBits)));
            int col = 0, rowIndex = 0;
            foreach (var row in toWriteLength)
            {
                _lockBitmap.SetPixel(col, rowIndex, WriteReadData.WriteData(_lockBitmap.GetPixel(col, rowIndex), row, null, null, null));
                ++col;
            }
            #endregion

            WriteReadData.SetDataMode();
            var toWrite = _byteOperations.SplitDataBytes(dataToEncrypt);
            int x = 0, y = 1;
            var lastIndex = toWrite.Count;
            foreach (var row in toWrite)
            {
                if (x >= ImageModifying.Width)
                {
                    y++; x = 0;
                }
                var p  = _lockBitmap.GetPixel(x, y);
                var np = WriteReadData.WriteData(p, null, row[0], row[1], row[2]);
                _lockBitmap.SetPixel(x, y, np);

                if (interactive && !skip)
                {
                    progress.SetData((int)Math.Ceiling((toWrite.IndexOf(row) / ((lastIndex - 1) * 1.0)) * 100), x, y, p.R, p.G, p.B, np.R, np.G, np.B);
                    if (progress.ShowDialog() == DialogResult.Cancel)
                    {
                        skip = true;
                    }
                }

                ++x;
            }
            // Unlock the bits.
            _lockBitmap.UnlockBits();
            return(_lockBitmap.GetImage());
        }