Esempio n. 1
0
        private void SavePage(Image image, ImagePageHeader pageHeader, int rowsInPage, bool lastPage)
        {
            var imageRows = image.Rows.Skip(pageHeader.Index * rowsInPage).Take(rowsInPage).ToArray();

            var pageHeaderPosition = BaseStream.Position;

            this.BaseStream.Position += 31;
            this.BaseStream.Position += pageHeader.PageSize;

            foreach (ImageRow imageRow in imageRows)
            {
                imageRow.HeaderAddress = (uint)BaseStream.Position;
                //Image Row Header
                WriteImageRowHeader(imageRow);

                imageRow.BodyAddress = (uint)BaseStream.Position;
                //Imabe body
                WriteImageBody(imageRow);
            }

            uint nextPagePosition = (uint)BaseStream.Position;

            BaseStream.Position = pageHeaderPosition;

            //Save page header
            Write(pageHeader.Data1);

            StringBuilder sb = new StringBuilder();

            sb.Append(pageHeader.FullSize.ToString("X").PadLeft(8, '0').ToLower() + " ");
            sb.Append(pageHeader.PageSize.ToString("X").PadLeft(8, '0').ToLower() + " ");
            if (lastPage)
            {
                sb.Append(((uint)0x7fffffff).ToString("X").PadLeft(8, '0').ToLower() + " ");
            }
            else
            {
                sb.Append(nextPagePosition.ToString("X").PadLeft(8, '0').ToLower() + " ");
            }
            Write(sb.ToString().ToCharArray());

            Write(pageHeader.Data2);

            foreach (ImageRow imageRow in imageRows)
            {
                Write(imageRow.HeaderAddress);
                Write(imageRow.BodyAddress);
                Write((uint)0x7fffffff);
            }

            BaseStream.Position = nextPagePosition;
        }
Esempio n. 2
0
        private ImagePageHeader ReadPageHeader()
        {
            ImagePageHeader ph = new ImagePageHeader();

            ph.Position = BaseStream.Position;

            ph.Data1 = ReadUInt16();

            char[] ch  = ReadChars(27);
            string str = new String(ch);

            ph.FullSize        = UInt32.Parse(str.Substring(0, 8), NumberStyles.HexNumber);
            ph.PageSize        = UInt32.Parse(str.Substring(9, 8), NumberStyles.HexNumber);
            ph.NextPageAddress = UInt32.Parse(str.Substring(18, 8), NumberStyles.HexNumber);

            ph.Data2 = ReadUInt16();

            return(ph);
        }