private bool encodeLSBBMP()
        {
            bool result = false;

            BmpFileHeaders bmpFileHeaders = FileFormatHelpers.readBmpFileHeaders(this.fileBytes);

            LSBEncodeDialog lSBEncodeDialog = new LSBEncodeDialog();

            if (lSBEncodeDialog.ShowDialog() == true)
            {
                EncodeQueryResult encodeQueryResult = lSBEncodeDialog.getResult();

                byte[] sourceByteArray = FileFormatHelpers.convertLayerToByteArray(encodeQueryResult.layers[encodeQueryResult.layers.Count - 1]);

                for (int index = (encodeQueryResult.layers.Count - 1); index >= 0; index--)
                {
                    if (index == 0)
                    {
                        FileFormatHelpers.encodeDataIntoFileBytesBmp(
                            ref bmpFileHeaders,
                            ref sourceByteArray,
                            ref this.fileBytes
                            );
                    }
                    else
                    {
                        LayerInformation layerTargetInformation = encodeQueryResult.layers[index - 1];
                        sourceByteArray = FileFormatHelpers.encodeDataIntoLayersFileBytes(
                            ref sourceByteArray,
                            layerTargetInformation
                            );
                    }

                    encodeQueryResult.layers.RemoveAt(index);
                }

                result = true;
            }

            return(result);
        }
Пример #2
0
        public static BmpFileHeaders readBmpFileHeaders(byte[] fileBytes)
        {
            BmpFileHeaders bmpFileHeaders = new BmpFileHeaders();
            BinaryReader   binaryReader   = new BinaryReader(new MemoryStream(fileBytes));

            bmpFileHeaders.header.signature  = binaryReader.ReadUInt16();
            bmpFileHeaders.header.fileSize   = binaryReader.ReadUInt32();
            bmpFileHeaders.header.reserved   = binaryReader.ReadUInt32();
            bmpFileHeaders.header.dataOffset = binaryReader.ReadUInt32();

            bmpFileHeaders.infoHeader.size            = binaryReader.ReadUInt32();
            bmpFileHeaders.infoHeader.width           = binaryReader.ReadUInt32();
            bmpFileHeaders.infoHeader.height          = binaryReader.ReadUInt32();
            bmpFileHeaders.infoHeader.planes          = binaryReader.ReadUInt16();
            bmpFileHeaders.infoHeader.bitsPerPixel    = binaryReader.ReadUInt16();
            bmpFileHeaders.infoHeader.compresion      = binaryReader.ReadUInt32();
            bmpFileHeaders.infoHeader.imageSize       = binaryReader.ReadUInt32();
            bmpFileHeaders.infoHeader.xPixelsPerM     = binaryReader.ReadUInt32();
            bmpFileHeaders.infoHeader.yPixelsPerM     = binaryReader.ReadUInt32();
            bmpFileHeaders.infoHeader.colorsUsed      = binaryReader.ReadUInt32();
            bmpFileHeaders.infoHeader.importantColors = binaryReader.ReadUInt32();

            return(bmpFileHeaders);
        }