Ejemplo n.º 1
0
 internal TPageInfo(TImgExportInfo aExportInfo, Bitmap aBmp)
 {
     Bmp        = aBmp;
     ExportInfo = aExportInfo;
     Prev       = null;
     Next       = null;
 }
Ejemplo n.º 2
0
 private bool GetNextImage(ref TImgExportInfo ExportInfo, Bitmap bmp)
 {
     if (bmp == null)
     {
         return(Owner.Document.ExportNext(null, ref ExportInfo));
     }
     using (Graphics gr = Graphics.FromImage(bmp))
     {
         gr.Clear(Color.White);
         gr.InterpolationMode = Owner.InterpolationMode;
         gr.SmoothingMode     = Owner.SmoothingMode;
         return(Owner.Document.ExportNext(gr, ref ExportInfo));
     }
 }
Ejemplo n.º 3
0
        private void ExportAllImages(FlexCelImgExport ImgExport, ImageFormat ImgFormat, ImageColorDepth ColorDepth)
        {
            TImgExportInfo ExportInfo = null; //For first page.
            int            i          = 0;

            do
            {
                string FileName = Path.GetDirectoryName(exportImageDialog.FileName)
                                  + Path.DirectorySeparatorChar
                                  + Path.GetFileNameWithoutExtension(exportImageDialog.FileName)
                                  + "_" + ImgExport.Workbook.SheetName
                                  + String.Format("_{0:0000}", i) +
                                  Path.GetExtension(exportImageDialog.FileName);
                using (FileStream ImageStream = new FileStream(FileName, FileMode.Create))
                {
                    CreateImg(ImageStream, ImgExport, ImgFormat, ColorDepth, ref ExportInfo);
                }
                i++;
            } while (ExportInfo.CurrentPage < ExportInfo.TotalPages);
        }
Ejemplo n.º 4
0
        private void ReloadDocument()
        {
            if (Document == null)
            {
                return;
            }
            PageInfo.Clear();
            if (FThumbnailLarge != null)             //Reload document is always called first for the big preview and later for the thumbs.
            {
                FirstPageExportInfo = TImgExportInfo.Clone(FThumbnailLarge.FirstPageExportInfo);
            }
            else
            {
                FirstPageExportInfo = Document.GetFirstPageExportInfo();
            }

            FTotalPages    = FirstPageExportInfo.TotalPages;
            SavedStartPage = 0;

            ResizeCanvas(new Point(0, 0));
            OnZoomChanged(new EventArgs());
        }
Ejemplo n.º 5
0
        internal Bitmap GetImage(int index)
        {
            TImgExportInfo ei = null;

            if (Count > 0)
            {
                ei = TImgExportInfo.Clone(this[Count - 1].ExportInfo);
            }
            else
            {
                ei = TImgExportInfo.Clone(Owner.FirstPageExportInfo);
            }

            for (int i = Count; i <= index; i++)
            {
                GetNextImage(ref ei, null);
                Add(new TPageInfo(TImgExportInfo.Clone(ei), null));
            }

            TPageInfo Pi = this[index];

            if (Pi.Bmp == null)
            {
                RectangleF Page = Pi.ExportInfo.ActiveSheet.PageBounds;
                Pi.Bmp = BitmapConstructor.CreateBitmap((int)(Page.Width * Owner.Zoom), (int)(Page.Height * Owner.Zoom));
                Pi.Bmp.SetResolution(96 * Owner.Zoom, 96 * Owner.Zoom);
                TImgExportInfo ExportInfo = null;
                if (index > 0)
                {
                    ExportInfo = TImgExportInfo.Clone(this[index - 1].ExportInfo);
                }
                else
                {
                    ExportInfo = TImgExportInfo.Clone(Owner.FirstPageExportInfo);
                }

                GetNextImage(ref ExportInfo, Pi.Bmp);
                CacheCount++;
            }

            //Bring the item to last position on the cache.
            if (Pi.Next != null)
            {
                Pi.Next.Prev = Pi.Prev;
                if (Pi.Prev != null)
                {
                    Pi.Prev.Next = Pi.Next;
                }
                else
                {
                    CacheFirst = Pi.Next;
                }
            }
            if (CacheFirst == null)
            {
                CacheFirst = Pi;
            }

            if (CacheLast != Pi)
            {
                Pi.Prev = CacheLast;
                if (CacheLast != null)
                {
                    CacheLast.Next = Pi;
                }
                CacheLast = Pi;
                Pi.Next   = null;
            }

            //If we have more bitmaps on the cache that what is allowed, delete the one at the first position.
            if (CacheFirst != null && CacheCount > 1 + Owner.CacheSize / (Owner.Zoom * Owner.Zoom))
            {
                if (CacheFirst.Next != null)
                {
                    CacheFirst.Bmp.Dispose();
                    CacheFirst.Bmp = null;
                    CacheCount--;

                    TPageInfo Next = CacheFirst.Next;
                    Next.Prev       = null;
                    CacheFirst.Next = null;
                    CacheFirst      = Next;
                }
            }

            Debug.Assert(CacheFirst == null || CacheFirst.Prev == null, "Error in cache");
            Debug.Assert(CacheLast == null || CacheLast.Next == null, "Error in cache");
            return(Pi.Bmp);
        }
Ejemplo n.º 6
0
        //The methods shows how to use FlexCelImgExport the "hard way", without using SaveAsImage.
        //For normal operation you should only need to call SaveAsImage, but you could use the code here
        //if you need to customize the ImgExport output, or if you need to get all the images as different files.
        private void CreateImg(Stream OutStream, FlexCelImgExport ImgExport, ImageFormat ImgFormat, ImageColorDepth Colors, ref TImgExportInfo ExportInfo)
        {
            TPaperDimensions pd = ImgExport.GetRealPageSize();

            PixelFormat RgbPixFormat = Colors != ImageColorDepth.TrueColor ? PixelFormat.Format32bppPArgb : PixelFormat.Format24bppRgb;
            PixelFormat PixFormat    = PixelFormat.Format1bppIndexed;

            switch (Colors)
            {
            case ImageColorDepth.TrueColor: PixFormat = RgbPixFormat; break;

            case ImageColorDepth.Color256: PixFormat = PixelFormat.Format8bppIndexed; break;
            }

            using (Bitmap OutImg = CreateBitmap(ImgExport.Resolution, pd, PixFormat))
            {
                Bitmap ActualOutImg = Colors != ImageColorDepth.TrueColor ? CreateBitmap(ImgExport.Resolution, pd, RgbPixFormat) : OutImg;
                try
                {
                    using (Graphics Gr = Graphics.FromImage(ActualOutImg))
                    {
                        Gr.FillRectangle(Brushes.White, 0, 0, ActualOutImg.Width, ActualOutImg.Height); //Clear the background
                        ImgExport.ExportNext(Gr, ref ExportInfo);
                    }

                    if (Colors == ImageColorDepth.BlackAndWhite)
                    {
                        FloydSteinbergDither.ConvertToBlackAndWhite(ActualOutImg, OutImg);
                    }
                    else
                    if (Colors == ImageColorDepth.Color256)
                    {
                        OctreeQuantizer.ConvertTo256Colors(ActualOutImg, OutImg);
                    }
                }
                finally
                {
                    if (ActualOutImg != OutImg)
                    {
                        ActualOutImg.Dispose();
                    }
                }

                OutImg.Save(OutStream, ImgFormat);
            }
        }