/// <summary> /// Gets the background image for the page /// </summary> /// <returns></returns> internal System.Drawing.Bitmap GetBackgroundImage(int subsample, bool resizeImage = false) { Verify.SubsampleRange(subsample); int width = _Page.Width; int height = _Page.Height; BG44Chunk[] backgrounds = _Page.PageForm?.GetChildrenItems <BG44Chunk>(); if ((backgrounds == null || backgrounds.Length == 0) && width > 0 && height > 0) { return(DjvuImage.CreateBlankImage(Brushes.White, width, height)); } // Get the composite background image Wavelet.IInterWavePixelMap backgroundMap = null; lock (LoadingLock) { foreach (BG44Chunk background in backgrounds) { if (backgroundMap == null) { // Get the initial image backgroundMap = background.BackgroundImage; } else { if (!IsBackgroundDecoded) { background.ProgressiveDecodeBackground(backgroundMap); } } } IsBackgroundDecoded = true; } Bitmap result = backgroundMap.GetPixelMap().ToImage(); if (resizeImage) { int newWidth = width / subsample; int newHeight = height / subsample; return(DjvuImage.ResizeImage(result, newWidth, newHeight)); } else { return(result); } }
internal DjvuNet.Graphics.Map GetBackgroundMap(bool rebuild = false) { if (!rebuild && IsBackgroundDecoded) { return(_Page.PageForm?.GetChildrenItems <BG44Chunk>().FirstOrDefault()?.BackgroundImage.GetPixelMap() ?? null); } else if (rebuild && IsBackgroundDecoded) { IsBackgroundDecoded = false; } int width = _Page.Width; int height = _Page.Height; BG44Chunk[] backgrounds = _Page.PageForm?.GetChildrenItems <BG44Chunk>(); if ((backgrounds == null || backgrounds.Length == 0) && width > 0 && height > 0) { return(new Graphics.PixelMap(new sbyte[width * height], width, height)); } // Get the composite background image Wavelet.IInterWavePixelMap backgroundMap = null; lock (LoadingLock) { foreach (BG44Chunk background in backgrounds) { if (backgroundMap == null) { // Get the initial image backgroundMap = background.BackgroundImage; } else { if (!IsBackgroundDecoded) { background.ProgressiveDecodeBackground(backgroundMap); } } } IsBackgroundDecoded = true; } return(backgroundMap.GetPixelMap()); }