Ejemplo n.º 1
0
        public System.Drawing.Bitmap BuildPageImage(bool rebuild = false)
        {
            const int subsample = 1;

            int       width  = _Page.Width / subsample;
            int       height = _Page.Height / subsample;
            GMap      map    = null;
            Rectangle rect   = new Rectangle(0, 0, width, height);
            Bitmap    retVal = null;

            if (rebuild || _Image == null)
            {
                map = _Page.GetMap(new GRect(0, 0, width, height), subsample, null);
                if (map == null)
                {
                    return(new Bitmap(width, height));
                }

                if (map.BytesPerPixel == 3)
                {
                    const PixelFormat format = PixelFormat.Format24bppRgb;
                    retVal = DjvuImage.ImageFromMap(map, rect, format);
                }
                else if (map.BytesPerPixel == 1)
                {
                    const PixelFormat format = PixelFormat.Format8bppIndexed;
                    retVal = DjvuImage.ImageFromMap(map, rect, format);
                }
            }
            else
            {
                retVal = _Image;
            }

            if (map.BytesPerPixel == 3 && IsInverted)
            {
                retVal = DjvuImage.InvertColor(retVal);
            }
            else if (map.BytesPerPixel == 1)
            {
                System.Drawing.Imaging.ColorPalette palette = retVal.Palette;

                if (!IsInverted)
                {
                    for (int i = 0; i < 256; i++)
                    {
                        palette.Entries[i] = Color.FromArgb(i, i, i);
                    }

                    retVal.Palette = palette;
                }
                else
                {
                    int j = 0;
                    for (int i = 0; i < 256; i++)
                    {
                        j = 255 - i;
                        palette.Entries[i] = Color.FromArgb(j, j, j);
                    }
                    retVal.Palette = palette;
                }
            }

            return(retVal);

            //int[] pixels = new int[width * height];

            //map.FillRgbPixels(0, 0, width, height, pixels, 0, width);
            //var image = ConvertDataToImage(pixels);

            //if (IsInverted == true)
            //    image = InvertImage(image);

            //return image;
        }