Ejemplo n.º 1
0
        public LeadSize SizeToPixels(LeadSize value)
        {
            if (value.IsEmpty)
            {
                return(LeadSize.Empty);
            }

            var resolution = this.Pages.DefaultResolution;

            return(LeadSize.Create(DocumentToPixels(resolution, value.Width), DocumentToPixels(resolution, value.Height)));
        }
Ejemplo n.º 2
0
        private RasterImage AddTextFooter(RasterImage image, string tag, int footerMaxHeight)
        {
            LeadRect bounds = LeadRect.Create(0, 0, image.Width, image.Height);

            using (var imageTag = CreateTextFooter(LeadSize.Create(bounds.Width, footerMaxHeight), tag))
            {
                bounds.Height += imageTag.Height;

                var bpp             = 24;
                var byteOrder       = RasterByteOrder.Bgr;
                var viewPerspective = RasterViewPerspective.TopLeft;

                if (image.ViewPerspective != viewPerspective)
                {
                    image.ChangeViewPerspective(viewPerspective);
                }

                if (image.BitsPerPixel != bpp || image.Order != byteOrder)
                {
                    var colorResCommand = new ColorResolutionCommand(
                        ColorResolutionCommandMode.InPlace,
                        bpp,
                        byteOrder,
                        RasterDitheringMethod.None,
                        ColorResolutionCommandPaletteFlags.Optimized,
                        null);
                    colorResCommand.Run(image);
                }

                RasterImage imageResult = new RasterImage(RasterMemoryFlags.Conventional, bounds.Width, bounds.Height, bpp, byteOrder, viewPerspective, null, null, 0);

                {
                    var combine = new CombineFastCommand(imageResult, bounds, LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy);
                    combine.Run(image);
                }

                {
                    var combine = new CombineFastCommand(imageResult, LeadRect.Create(bounds.X, image.Height, bounds.Width, bounds.Height - image.Height), LeadPoint.Create(0, 0), CombineFastCommandFlags.SourceCopy);
                    combine.Run(imageTag);
                }
                return(imageResult);
            }
        }
Ejemplo n.º 3
0
        private void FillImageList(RasterImage image)
        {
            using (RasterCodecs codecs = new RasterCodecs())
            {
                ImageListControl.Items.Clear();

                for (int index = 1; index <= image.PageCount; index++)
                {
                    image.Page = index;
                    // Create the item of the image list
                    ImageViewerItem item = new ImageViewerItem();
                    item.Size  = LeadSize.Create(120, 120);
                    item.Text  = "Page: " + (index - 1).ToString();
                    item.Image = image.Clone();
                    item.Tag   = index;

                    // Add the item to the image list
                    ImageListControl.Items.Add(item);
                }

                ImageListControl.Items[0].IsSelected = true;
                _viewer.Image = ImageListControl.Items[0].Image;
            }
        }
Ejemplo n.º 4
0
        public LeadSize SizeToDocument(LeadSize value)
        {
            var resolution = this.Pages.DefaultResolution;

            return(LeadSize.Create(PixelsToDocument(resolution, (int)value.Width), PixelsToDocument(resolution, (int)value.Height)));
        }
Ejemplo n.º 5
0
        private void InitClass( )
        {
            _viewer             = new ImageViewer();
            _viewer.Dock        = DockStyle.Fill;
            _viewer.BorderStyle = BorderStyle.None;
            _pnlViewer.Controls.Add(_viewer);
            _viewer.BringToFront();
            _viewer.AllowDrop         = true;
            _viewer.AutoDisposeImages = false;

            // Create a new RasterImageList control.
            ImageViewerVerticalViewLayout viewLayout = new Leadtools.Controls.ImageViewerVerticalViewLayout()
            {
                Columns = 1
            };

            ImageListControl        = new ImageViewer(viewLayout);
            Size                    = new Size(200, 200);
            ImageListControl.Bounds = new Rectangle(new Point(0, 0), Size);

            ImageListControl.SelectedItemBorderColor     = Color.Red;
            ImageListControl.SelectedItemBackgroundColor = Color.LightBlue;
            ImageListControl.BackColor                = Color.LightGray;
            ImageListControl.BorderStyle              = BorderStyle.FixedSingle;
            ImageListControl.ImageBorderThickness     = 1;
            ImageListControl.ImageHorizontalAlignment = ControlAlignment.Far;
            ImageListControl.ImageVerticalAlignment   = ControlAlignment.Center;
            ImageListControl.ItemBackgroundColor      = Color.LightGray;
            ImageListControl.ItemBorderThickness      = 0;
            ImageListControl.ItemPadding              = new Padding(20);
            ImageListControl.ItemTextColor            = Color.Black;
            ImageListControl.ItemSize     = LeadSize.Create(60, 80);
            ImageListControl.ItemSizeMode = ControlSizeMode.Fit;
            ImageListControl.Dock         = DockStyle.Fill;
            RasterPaintProperties paintProperties = ImageListControl.PaintProperties;

            paintProperties.PaintDisplayMode         = RasterPaintDisplayModeFlags.Bicubic;
            ImageListControl.PaintProperties         = paintProperties;
            ImageListControl.Height                  = _viewer.Height;
            ImageListControl.TextHorizontalAlignment = ControlAlignment.Center;
            ImageListControl.TextVerticalAlignment   = ControlAlignment.Center;
            ImageListControl.InteractiveModes.BeginUpdate();
            ImageListControl.InteractiveModes.Add(new ImageViewerSelectItemsInteractiveMode()
            {
                SelectionMode = ImageViewerSelectionMode.Single
            });
            ImageListControl.InteractiveModes.EndUpdate();
            ImageListControl.SelectedItemsChanged += new EventHandler(ImageListControl_SelectedItemsChanged);
            ImageListControl.AutoDisposeImages     = false;

            // Add the RasterImageList to the control collection.
            _pnlImageList.Controls.Add(ImageListControl);

            PlayingAnnimation = false;
            StopAnimation     = false;
            LoopAnimation     = false;

            ActiveList = ActiveImageLists.ColorList;

            ImagesList     = new List <RasterImage>();
            ColorList      = new List <RasterImage>();
            OpacityList    = new List <RasterImage>();
            PreOpacityList = new List <RasterImage>();

            ((MainForm)MdiParent).ClearCheck();
            ((MainForm)MdiParent).SetCheck(ActiveList);

            RenderHeight   = DefaultViewerHeight;
            RenderWidth    = DefaultViewerWidth;
            AnimationDelay = DefaultDelay;
        }
        public static void SaveDocument(LEADDocument document, ObservableCollection <DocumentItemData> documentsCollection, OcrOutputFormat format = OcrOutputFormat.None, int replaceItemAtIndex = -1, bool autoSerializeDocuments = true)
        {
            string thumbnailPath = Path.Combine(CacheDirectory, document.DocumentId, $"thumbnail.jpeg");

            // Create new document item data
            DateTime currentDatetime = DateTime.Now;

            if (string.IsNullOrWhiteSpace(document.Name))
            {
                if (replaceItemAtIndex == -1) // we are adding new document and not replacing existing one, so use the old document name
                {
                    document.Name = FindUniqueDocumentName(documentsCollection);
                }
                else
                {
                    document.Name = documentsCollection[replaceItemAtIndex].Title;
                }
            }

            string annotationsFilePath = Path.Combine(ApplicationDirectory, "Documents", $"{document.Name}.xml");

            DocumentItemData newDocumentItemData = new DocumentItemData();

            newDocumentItemData.DocumentId            = document.DocumentId;
            newDocumentItemData.DocumentThumbnailPath = thumbnailPath;
            newDocumentItemData.AnnotationsFilePath   = annotationsFilePath;
            newDocumentItemData.Title          = document.Name;
            newDocumentItemData.Date           = currentDatetime;
            newDocumentItemData.DocumentFormat = format;

            if (Device.RuntimePlatform == Device.iOS)
            {
                // Save the original file path that was loaded from gallery, so we can delete it later when we convert this document in
                // order to save space since we won't need this file anymore.
                // only do this for the newly created documents and not the already converted ones.
                if (format == OcrOutputFormat.None)
                {
                    newDocumentItemData.DocumentFiles = GetDocumentSourceFiles(document);
                }
            }

            IEnumerable <DocumentItemData> items = documentsCollection.Where(x => x.DocumentId.Equals(document.DocumentId));

            if ((items != null && items.Count() > 0) || replaceItemAtIndex != -1)
            {
                // Document already exist, so just update it
                int index = (replaceItemAtIndex != -1) ? replaceItemAtIndex : documentsCollection.IndexOf(items.ElementAt(0));
                documentsCollection.Insert(index, newDocumentItemData);
                documentsCollection.RemoveAt(index + 1);
            }
            else
            {
                documentsCollection.Add(newDocumentItemData);
            }

            if (autoSerializeDocuments)
            {
                SerializeDocuments(documentsCollection);
            }

            document.SaveToCache();

            if (document.Pages != null && document.Pages.Count > 0)
            {
                using (var codecs = new RasterCodecs())
                {
                    try
                    {
                        LeadSize thumbnailSize = LeadSize.Create((int)(document.Images.ThumbnailPixelSize.Width * 1.5), (int)(document.Images.ThumbnailPixelSize.Height * 1.5));
                        using (var rasterImage = document.Pages[0].GetImage())
                        {
                            var thumbnailImage = rasterImage.CreateThumbnail(thumbnailSize.Width, thumbnailSize.Height, 32, RasterViewPerspective.TopLeft, RasterSizeFlags.Bicubic);
                            if (thumbnailImage == null)
                            {
                                thumbnailImage = document.Pages[0].GetThumbnailImage();
                            }
                            codecs.Save(thumbnailImage, thumbnailPath, RasterImageFormat.Jpeg, 0);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        codecs.Save(document.Pages[0].GetThumbnailImage(), thumbnailPath, RasterImageFormat.Jpeg, 0);
                    }
                }
            }
        }