예제 #1
0
        /// <summary>
        /// …
        /// </summary>
        /// <param name="output">…</param>
        /// <param name="bmpInput">…</param>
        private static void WriteBMPHeaders(MemoryStream output, Bitmap bmpInput)
        {
            int nWidth  = bmpInput.Width;
            int nHeight = bmpInput.Height;

            BitmapFileHeader hdrFile   = new BitmapFileHeader();
            BitmapInfoHeader hdrBmpInf = new BitmapInfoHeader();

            hdrFile.Init();
            hdrBmpInf.Init();

            // Get some values in advance:

            UInt32 uImageSize     = (UInt32)(nWidth * nHeight);
            UInt32 uFileSize      = (UInt32)(hdrFile.bfOffBits + uImageSize);
            UInt32 uXPelsPerMeter = (UInt32)Math.Round(bmpInput.HorizontalResolution * InchesPerMeter, 0);
            UInt32 uYPelsPerMeter = (UInt32)Math.Round(bmpInput.VerticalResolution * InchesPerMeter, 0);

            // Set file header values:

            hdrFile.bfSize = uFileSize;

            // Set image header values:

            hdrBmpInf.biWidth         = nWidth;
            hdrBmpInf.biHeight        = nHeight;
            hdrBmpInf.biPlanes        = 1;
            hdrBmpInf.biBitCount      = 32;
            hdrBmpInf.biCompression   = 0;
            hdrBmpInf.biSizeImage     = uImageSize;
            hdrBmpInf.biXPelsPerMeter = (int)uXPelsPerMeter;
            hdrBmpInf.biYPelsPerMeter = (int)uYPelsPerMeter;
            hdrBmpInf.biClrUsed       = hdrBmpInf.biClrImportant = 0;

            // Write headers:

            byte[] dataHdrFile   = StructureToByteArray(hdrFile);
            byte[] dataHdrBmpInf = StructureToByteArray(hdrBmpInf);

            output.Write(dataHdrFile, 0, dataHdrFile.Length);
            output.Write(dataHdrBmpInf, 0, dataHdrBmpInf.Length);
        }
예제 #2
0
        /// <summary>
        /// …
        /// </summary>
        /// <param name="output">…</param>
        /// <param name="bmpInput">…</param>
        private static void WriteBMPHeaders(MemoryStream output, Bitmap bmpInput)
        {
            int nWidth = bmpInput.Width;
             int nHeight = bmpInput.Height;

             BitmapFileHeader hdrFile = new BitmapFileHeader();
             BitmapInfoHeader hdrBmpInf = new BitmapInfoHeader();
             hdrFile.Init();
             hdrBmpInf.Init();

             // Get some values in advance:

             UInt32 uImageSize = (UInt32)(nWidth * nHeight);
             UInt32 uFileSize = (UInt32)(hdrFile.bfOffBits + uImageSize);
             UInt32 uXPelsPerMeter = (UInt32)Math.Round(bmpInput.HorizontalResolution * InchesPerMeter, 0);
             UInt32 uYPelsPerMeter = (UInt32)Math.Round(bmpInput.VerticalResolution * InchesPerMeter, 0);

             // Set file header values:

             hdrFile.bfSize = uFileSize;

             // Set image header values:

             hdrBmpInf.biWidth = nWidth;
             hdrBmpInf.biHeight = nHeight;
             hdrBmpInf.biPlanes = 1;
             hdrBmpInf.biBitCount = 32;
             hdrBmpInf.biCompression = 0;
             hdrBmpInf.biSizeImage = uImageSize;
             hdrBmpInf.biXPelsPerMeter = (int)uXPelsPerMeter;
             hdrBmpInf.biYPelsPerMeter = (int)uYPelsPerMeter;
             hdrBmpInf.biClrUsed = hdrBmpInf.biClrImportant = 0;

             // Write headers:

             byte[] dataHdrFile = StructureToByteArray(hdrFile);
             byte[] dataHdrBmpInf = StructureToByteArray(hdrBmpInf);

             output.Write(dataHdrFile, 0, dataHdrFile.Length);
             output.Write(dataHdrBmpInf, 0, dataHdrBmpInf.Length);
        }