예제 #1
0
        public BigBitmap(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new Exception();
            }
            FilePath = filePath;

            Mmf     = MemoryMappedFile.CreateFromFile(filePath);
            MmfInfo = new FileInfo(filePath);

            if (MmfInfo.Length < VirtualSize)
            {
                VirtualSize = MmfInfo.Length;
            }


            // File.SetAttributes(filePath, FileAttributes.Normal);
            Reader = Mmf.CreateViewAccessor(Offset, VirtualSize);

            if (!Reader.CanRead)
            {
                throw new InvalidOperationException("File cannot be read");
            }

            MemoryMappedPosition = 0;
            FileHeader           = BigBitmapHeader.GetHeader(Reader, out MemoryMappedPosition);
            //MemoryMappedPostion = 22
            FileInfoHeader = BigBitmapInfoHeader.GetInfoHeader(Reader, ref MemoryMappedPosition);
            //MemoryMappedPostion = 70
            Initilize();
        }
예제 #2
0
 private BigBitmap(MemoryMappedViewAccessor Accessor, BigBitmapHeader Header, BigBitmapInfoHeader Info, string filePath)
 {
     Reader         = Accessor;
     FileHeader     = Header;
     FileInfoHeader = Info;
     FilePath       = filePath;
     Initilize();
 }
예제 #3
0
        public static BigBitmap CreateBigBitmap(string filePath, long Width, long Height, int HorizantalRes, int VerticalRes, byte BackGround_Red, byte BackGround_Green, byte BackGround_Blue)
        {
            if (Width * Height > long.MaxValue - 70)
            {
                throw new ArgumentOutOfRangeException("Width*Height", "Maximum file Size Exceeds Max INT64 Size, use lower Dimension Size or lower BPP (Which is not Supported YET!)");
            }

            var rowSize = (long)Math.Floor(((24 * (double)Width) + 31) / 32) * 4;
            var padding = rowSize - Width * 3;

            BigBitmapHeader     header     = null;
            BigBitmapInfoHeader headerInfo = null;

            using (var fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                header = new BigBitmapHeader()
                {
                    FileSize = 70 + Height * ((Width * 3) + padding)
                };

                var headerData = header.CreateBigBitmapHeader();
                fileStream.Write(headerData, 0, headerData.Length);
                fileStream.Flush();

                headerInfo = new BigBitmapInfoHeader()
                {
                    BitmapHeight = Height, BitsPerPixel = 24, ColorPlanes = 1, BitmapWidth = Width, HorizantalResolution = HorizantalRes, VerticalResolution = VerticalRes
                };

                headerData = headerInfo.CreateInfoHeaderData(Height * ((Width * 3) + padding));
                fileStream.Write(headerData, 0, headerData.Length);

                var colorBytes = new byte[] { BackGround_Blue, BackGround_Green, BackGround_Red };
                headerData = new byte[padding];

                fileStream.Flush();

                for (long i = 0; i < Height; i++)
                {
                    for (long k = 0; k < Width; k++)
                    {
                        fileStream.Write(colorBytes, 0, colorBytes.Length);
                    }
                    //headerData = byte[padding]
                    fileStream.Write(headerData, 0, headerData.Length);
                }

                fileStream.Flush();
                fileStream.Close();
            }


            return(new BigBitmap(MemoryMappedFile.CreateFromFile(filePath).CreateViewAccessor(), header, headerInfo, filePath));
        }
예제 #4
0
        public static BigBitmapInfoHeader GetInfoHeader(MemoryMappedViewAccessor Reader, ref int MMPosition)
        {
            //MMPosition = 18;
            var header = new BigBitmapInfoHeader();

            // HeaderSize = reader.ReadInt32(),
            header.BitmapWidth = Reader.ReadInt64(MMPosition);
            MMPosition        += 8;

            header.BitmapHeight = Reader.ReadInt64(MMPosition);
            MMPosition         += 8;

            header.ColorPlanes = Reader.ReadInt16(MMPosition);
            MMPosition        += 2;

            header.BitsPerPixel = Reader.ReadInt16(MMPosition);
            MMPosition         += 2;

            header.CompressinoMethod = Reader.ReadInt32(MMPosition);
            MMPosition += 4;

            header.ColorDataSize = Reader.ReadInt64(MMPosition);
            MMPosition          += 8;

            header.HorizantalResolution = Reader.ReadInt32(MMPosition);
            MMPosition += 4;

            header.VerticalResolution = Reader.ReadInt32(MMPosition);
            MMPosition += 4;

            header.Colors = Reader.ReadInt32(MMPosition);
            MMPosition   += 4;

            header.IColors = Reader.ReadInt32(MMPosition);
            MMPosition    += 4;

            return(header);
        }