Example #1
0
            static byte[] GetHeader(uint fileSize, PDFiumBitmap bitmap, double dpiX, double dpiY)
            {
                const double MetersPerInch = 0.0254;

                byte[] header = new byte[BmpHeaderSize + DibHeaderSize];

                using (var ms = new MemoryStream(header))
                    using (var writer = new BinaryWriter(ms))
                    {
                        writer.Write((byte)'B');
                        writer.Write((byte)'M');
                        writer.Write(fileSize);
                        writer.Write(0u);
                        writer.Write(PixelArrayOffset);
                        writer.Write(DibHeaderSize);
                        writer.Write(bitmap.Width);
                        writer.Write(-bitmap.Height);                 // top-down image
                        writer.Write((ushort)1);
                        writer.Write((ushort)(bitmap.BytesPerPixel * 8));
                        writer.Write(CompressionMethod);
                        writer.Write(0);
                        writer.Write((int)Math.Round(dpiX / MetersPerInch));
                        writer.Write((int)Math.Round(dpiY / MetersPerInch));
                        writer.Write(0L);
                        writer.Write(MaskR);
                        writer.Write(MaskG);
                        writer.Write(MaskB);
                        if (bitmap.Format == BitmapFormats.FPDFBitmap_BGRA)
                        {
                            writer.Write(MaskA);
                        }
                    }
                return(header);
            }
Example #2
0
            public BmpStream(PDFiumBitmap bitmap, double dpiX, double dpiY)
            {
                if (bitmap.Format == BitmapFormats.FPDFBitmap_Gray)
                {
                    throw new NotSupportedException($"Bitmap format {bitmap.Format} is not yet supported.");
                }

                _bitmap    = bitmap;
                _rowLength = (uint)bitmap.BytesPerPixel * (uint)bitmap.Width;
                _stride    = (((uint)bitmap.BytesPerPixel * 8 * (uint)bitmap.Width + 31) / 32) * 4;
                _length    = PixelArrayOffset + _stride * (uint)bitmap.Height;
                _header    = GetHeader(_length, _bitmap, dpiX, dpiY);
                _pos       = 0;
            }
Example #3
0
        protected virtual void Dispose(bool disposing)
        {
            if (IsDisposed)
            {
                return;
            }

            if (_bitmap != null)
            {
                _bitmap.Dispose();
            }

            _bitmap = null;

            IsDisposed = true;
            if (disposing)
            {
                GC.SuppressFinalize(this);
            }
        }