Beispiel #1
0
        /// <summary>
        /// Creates a new TifImage that is "this" with the passed in image appended to the end of it.
        /// </summary>
        /// <param name="toAppend">The image you want to append to this one</param>
        /// <returns>A brand new image that contains "this" + toAppend</returns>
        public TifImage Merge(TifImage toAppend)
        {
            using (var stream = new MemoryStream())
            {
                foreach (var image in new[] { this, toAppend })
                {
                    for (var i = 1; i <= image.TotalPages; i++)
                    {
                        codec.Save(image.ImageData,
                                   stream,
                                   RasterImageFormat.CcittGroup4,
                                   1,
                                   i,
                                   i,
                                   0,
                                   CodecsSavePageMode.Append);

                        RasterTagMetadata tagMetaData;
                        if (image.tagsByPageNumber.TryGetValue(i, out tagMetaData))
                        {
                            codec.WriteTag(stream, i, tagMetaData);
                        }
                    }
                }

                return(new TifImage(stream));
            }
        }
        /*public bool SplitDocuments(InboundDocsView ibDoc, 
                                   AssociatedDoc assDoc, 
                                   Func<IEnumerable<int>> pages,
                                   Action<int> onPageExtracted)
        {
            if (imageHolder.ImageModified)
            {
                if (MessageBox.Show(@"Save document image changes?", @"Save Image", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
                {
                    ImagesEventManager.Instance.Raise(new ImagesSavingEventArgs());
                }
            }

            var assDocImage = imagesDal.GetByDocId(assDoc.Id, ImagesDtoType.Associated);
            if (assDocImage != null)
            {
                Logger.InfoFormat("Associated document for id={0} already exists. Nothing to do.", assDoc.Id);
                return true;
            }

            var sourceDto = imagesDal.GetByDocId(ibDoc.Id, ImagesDtoType.Inbound);
            var sourceImage = sourceDto.GetMarkupTifImage();
            if (imageHolder.TotalPages == 1)
            {
                var destImage = sourceImage.Clone();                
                return true;
            }

            var pages = pages();
            if (pages == null)
            {
                return false;
            }

            var pageList = pages.ToList();
            var assDocPages = sourceImage.ExtractPages(pageList, onPageExtracted);
            var remainder = sourceImage.ExtractPagesInverse(pageList);
            return true;
        }*/

        public DocumentSplitResult Split(TifImage sourceImage, IEnumerable<int> pages, Action<int> onPageExtracted)
        {            
            if (sourceImage.TotalPages == 1)
            {
                var destImage = sourceImage.Clone();
                return new DocumentSplitResult(destImage);
            }
            
            if (pages == null)
            {
                return null;
            }

            var pageList = pages.ToList();
            var splitPages = sourceImage.ExtractPages(pageList, onPageExtracted);
            var remainder = sourceImage.ExtractPagesInverse(pageList, onPageExtracted);
            return new DocumentSplitResult(splitPages, remainder);
        }
Beispiel #3
0
        private void LoadPages(TifImage tifImage)
        {
            if (tifImage == null)
            {
                return;
            }
                        
            RasterPaintProperties paintProp = imageList.PaintProperties;
            paintProp.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray;
            
            image = tifImage.ImageData;
            imageList.Items.Clear();
            for (var i = 1; i <= image.PageCount; ++i)
            {
                RasterImageListItem imageItem = new RasterImageListItem(image, i, "Page " + i);
                imageList.Items.Add(imageItem);
            }

            LoadCheckBox(image.PageCount);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new TifImage that is "this" with the passed in image appended to the end of it.
        /// </summary>
        /// <param name="toAppend">The image you want to append to this one</param>
        /// <returns>A brand new image that contains "this" + toAppend</returns>
        public TifImage Merge(TifImage toAppend)
        {
            using (var stream = new MemoryStream())
            {                
                foreach (var image in new[] { this, toAppend} )
                {
                    for (var i = 1; i <= image.TotalPages; i++)
                    {
                        codec.Save(image.ImageData, 
                                   stream, 
                                   RasterImageFormat.CcittGroup4, 
                                   1, 
                                   i, 
                                   i, 
                                   0,
                                   CodecsSavePageMode.Append);

                        RasterTagMetadata tagMetaData;
                        if (image.tagsByPageNumber.TryGetValue(i, out tagMetaData))
                        {
                            codec.WriteTag(stream, i, tagMetaData);
                        }                    
                    }
                }
                
                return new TifImage(stream);
            }
        }
        private void PersistDocumentMerge(List<InboundDocsView> selectedViews, ImagesDto[] imagesDto, TifImage mergedImage)
        {
            using (var ts = new TransactionScope())
            {
                var mergedBytes = mergedImage.GetImageBytes();

                imagesDto[0].MarkupImage = mergedBytes;
                imagesDal.Update(imagesDto[0]);
                var viewToDiscard = selectedViews[1];
                inboundDocsDal.UpdateStatus((int)viewToDiscard.Id, InboundDoc.DISCARDED);
                viewToDiscard.DocStatusCode = InboundDoc.DISCARDED;
                ApplyMergeResultsToView(viewToDiscard);
                ts.Complete();
            }           
        }
Beispiel #6
0
 public PageSelection(TifImage image)
 {
     InitializeComponent();
     LoadPages(image);
 }
 internal DocumentSplitResult(TifImage splitPages, TifImage remainder = null)
 {
     Remainder = remainder;
     SplitPages = splitPages;
 }