示例#1
0
        public static void MergeFiles(string mainFile, string appendFile, bool annotation)
        {
            if (MergeFilesByCopy(mainFile, appendFile))
            {
                return;
            }


            RasterCodecs codec = new RasterCodecs();
            RasterImage  image = null;

            RasterTagMetadata[] tagsData = null;  // stores the annotatin
            RasterImage         image2   = null;

            try
            {
                // load the image and annotation information for the
                // append file.
                image = codec.Load(appendFile);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(appendFile, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(appendFile, mainFile, pageCount);
                statusForm.Show();
                statusForm.Refresh();
                image2 = codec.Load(mainFile);
                int mainPageNumber = image2.PageCount;
                for (int i = 0; i < pageCount; ++i)
                {
                    codec.Save(image, mainFile, RasterImageFormat.CcittGroup4, 1, i + 1, i + 1, 1, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[i] != null))
                        {
                            codec.WriteTag(mainFile, mainPageNumber + i + 1, tagsData[i]);
                        }
                    }
                    statusForm.ShowPageInfo(i);
                }
                statusForm.Close();
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }
                if (image2 != null)
                {
                    image2.Dispose();
                }
            }
        }
示例#2
0
 private void LoadTagsMetaData(Stream stream)
 {
     for (int i = 0; i < TotalPages; i++)
     {
         var pageNumber = i + 1;
         RasterTagMetadata tagMetaData = codec.ReadTag(stream, pageNumber, RasterTagMetadata.AnnotationTiff);
         if (tagMetaData != null)
         {
             tagsByPageNumber.Add(pageNumber, tagMetaData);
         }
     }
 }
示例#3
0
        public void LoadFromStream(Stream stream)
        {
            RasterCodecs codecs = TifEditor.Codecs;

            if (tifEditor.Viewer.IsImageAvailable)
            {
                int totalPageCount = tifEditor.Viewer.Image.PageCount;
                tagsData = new RasterTagMetadata[totalPageCount];
                for (int i = 0; i < totalPageCount; ++i)
                {
                    tagsData[i] = codecs.ReadTag(stream, i + 1, RasterTagMetadata.AnnotationTiff);
                }
            }
        }
示例#4
0
        private static void DoExtraction(string srcFileName, string destFileName, int[] pageNumList, bool annotation)
        {
            RasterCodecs codec = new RasterCodecs();
            RasterImage image = null;
            RasterTagMetadata[] tagsData = null;

            try
            {
                image = codec.Load(srcFileName);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(srcFileName, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                int listCount = pageNumList.Length;
                if (File.Exists(destFileName))
                {
                    File.Delete(destFileName);
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(srcFileName, destFileName, listCount);
                statusForm.Show();
                statusForm.Refresh();
                for (int i = 0; i < listCount; ++i)
                {
                    codec.Save(image, destFileName, RasterImageFormat.CcittGroup4, 1, pageNumList[i], pageNumList[i], i, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[pageNumList[i] - 1] != null))
                        {
                            codec.WriteTag(destFileName, i + 1, tagsData[pageNumList[i]-1]);
                        }
                    }
                    statusForm.ShowPageInfo(pageNumList[i]);
                }

                if (image.PageCount > listCount)
                {
                    int deleteCount = 0;
                    for (int i = 1; i <= pageCount; ++i)
                    {
                        if (PageNumberFound(i, pageNumList))
                        {
                            image.RemovePageAt(i+deleteCount);
                            deleteCount--;
                        }
                    }
                    codec.Save(image, srcFileName, RasterImageFormat.CcittGroup4, 1, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);
                    if (annotation)
                    {
                        int newPageIndex = 0;
                        for (int i = 0; i < pageCount; ++i)
                        {
                            if (!PageNumberFound(i+1, pageNumList) && (tagsData != null) && (tagsData[i] != null))
                            {
                               codec.WriteTag(srcFileName, ++newPageIndex, tagsData[i]);
                            }
                        }
                    }
                    
                }
                else
                {
                    File.Delete(srcFileName);
                }
                statusForm.Close();

            }
            finally
            {
                if (image != null) {
                    image.Dispose();
                }
            }

        }
示例#5
0
        public static void MergeFiles(string mainFile, string appendFile, bool annotation)
        {


            if (MergeFilesByCopy(mainFile, appendFile))
            {
                return;
            }
            

            RasterCodecs codec = new RasterCodecs();
            RasterImage image = null;
            RasterTagMetadata[] tagsData = null;  // stores the annotatin
            RasterImage image2 = null;
            try
            {
                // load the image and annotation information for the 
                // append file.
                image = codec.Load(appendFile);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(appendFile, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(appendFile, mainFile, pageCount);
                statusForm.Show();
                statusForm.Refresh();
                image2 = codec.Load(mainFile);
                int mainPageNumber = image2.PageCount;
                for (int i = 0; i < pageCount; ++i)
                {
                    codec.Save(image, mainFile, RasterImageFormat.CcittGroup4, 1,  i + 1, i + 1, 1, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[i] != null))
                        {
                            codec.WriteTag(mainFile, mainPageNumber + i + 1, tagsData[i]);
                        }
                    }
                    statusForm.ShowPageInfo(i);
                }
                statusForm.Close();

            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }
                if (image2 != null)
                {
                    image2.Dispose();
                }
            }


        }
示例#6
0
        private static void DoExtraction(string srcFileName, string destFileName, int[] pageNumList, bool annotation)
        {
            RasterCodecs codec = new RasterCodecs();
            RasterImage  image = null;

            RasterTagMetadata[] tagsData = null;

            try
            {
                image = codec.Load(srcFileName);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(srcFileName, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                int listCount = pageNumList.Length;
                if (File.Exists(destFileName))
                {
                    File.Delete(destFileName);
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(srcFileName, destFileName, listCount);
                statusForm.Show();
                statusForm.Refresh();
                for (int i = 0; i < listCount; ++i)
                {
                    codec.Save(image, destFileName, RasterImageFormat.CcittGroup4, 1, pageNumList[i], pageNumList[i], i, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[pageNumList[i] - 1] != null))
                        {
                            codec.WriteTag(destFileName, i + 1, tagsData[pageNumList[i] - 1]);
                        }
                    }
                    statusForm.ShowPageInfo(pageNumList[i]);
                }

                if (image.PageCount > listCount)
                {
                    int deleteCount = 0;
                    for (int i = 1; i <= pageCount; ++i)
                    {
                        if (PageNumberFound(i, pageNumList))
                        {
                            image.RemovePageAt(i + deleteCount);
                            deleteCount--;
                        }
                    }
                    codec.Save(image, srcFileName, RasterImageFormat.CcittGroup4, 1, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);
                    if (annotation)
                    {
                        int newPageIndex = 0;
                        for (int i = 0; i < pageCount; ++i)
                        {
                            if (!PageNumberFound(i + 1, pageNumList) && (tagsData != null) && (tagsData[i] != null))
                            {
                                codec.WriteTag(srcFileName, ++newPageIndex, tagsData[i]);
                            }
                        }
                    }
                }
                else
                {
                    File.Delete(srcFileName);
                }
                statusForm.Close();
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }
            }
        }