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(); var test2 = WriteReadData.GetID(); SetConfPixel(WriteReadDataIdPosition, WriteReadData.GetID()); if (DataCompression != null) { dataToEncrypt = DataCompression.Compression(dataToEncrypt); SetConfPixel(DataCompressionIdPosition, DataCompression.GetID()); } else { SetConfPixel(DataCompressionIdPosition, 0b00000000); } 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()); 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 = 3; // col = 0, rowIndex = 0; foreach (var row in toWriteLength) { imageArray[col] = (byte)((imageArray[col] & 0b11110000) | row); //_lockBitmap.SetPixel(col, rowIndex, WriteReadData.WriteData(_lockBitmap.GetPixel(col, rowIndex), row, null, null, null)); col += 4; // ++col; } #endregion WriteReadData.SetDataMode(); var toWrite = _byteOperations.SplitDataBytes(dataToEncrypt); int x = 0, y = 0; var lastIndex = toWrite.Count; foreach (var row in toWrite) { byte bR = imageArray[y + 0]; byte bG = imageArray[y + 1]; byte bB = imageArray[y + 2]; imageArray[y + 0] = (byte)((bR & 0b11110000) | row[0]); imageArray[y + 1] = (byte)((bG & 0b11110000) | row[1]); imageArray[y + 2] = (byte)((bB & 0b11110000) | row[2]); //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, bR, bG, bB, imageArray[y * ImageModifying.Width * 4 + x * 4 + 0], imageArray[y * ImageModifying.Width * 4 + x * 4 + 1], imageArray[y * ImageModifying.Width * 4 + x * 4 + 2]); if (progress.ShowDialog() == DialogResult.Cancel) { skip = true; } } y += 4; } var test1 = imageArray; return(ImageHelper.ArrToBmp(imageArray, ImageModifying.Width, ImageModifying.Height)); // Unlock the bits. //_lockBitmap.UnlockBits(); //return _lockBitmap.GetImage(); }