public string DetectMICRLine(string ImageFile)
        {
            string errorCode;

            // CloseNativeImage();
            _imageId = _gdPictureImaging.CreateGdPictureImageFromFile(ImageFile);
            _gdPictureImaging.AutoDeskew(_imageId);
            // System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            // sw.Start();
            int           Length = 36;
            StringBuilder result = new StringBuilder(_gdPictureImaging.MICRDoMICR(_imageId, MICRFont.MICRFontE13B,
                                                                                  MICRContext.MICRContextLineFinding, "0123456789ABCD", Length));

            result = result.Replace(System.Convert.ToString('\0'), "?");
            // sw.Stop();
            GdPictureStatus status = _gdPictureImaging.GetStat();

            if (status == GdPictureStatus.OK)
            {
                result.ToString();
            }
            else
            {
                errorCode = status.ToString();
                return(errorCode);
            }
            _gdPictureImaging.Dispose();

            return(result.ToString());
        }
Exemple #2
0
        public static string castTopdf(string file, GdPictureImaging oGdPictureImaging, GdPicturePDF oGdPicturePDF)
        {
            string str = "";

            oGdPictureImaging.TiffOpenMultiPageForWrite(false);
            int num = oGdPictureImaging.CreateGdPictureImageFromFile(file);

            if (num != 0)
            {
                oGdPicturePDF.NewPDF();
                if (oGdPictureImaging.TiffIsMultiPage(num))
                {
                    int  num1 = oGdPictureImaging.TiffGetPageCount(num);
                    bool flag = true;
                    int  num2 = 1;
                    while (num2 <= num1)
                    {
                        oGdPictureImaging.TiffSelectPage(num, num2);
                        oGdPicturePDF.AddImageFromGdPictureImage(num, false, true);
                        if (oGdPicturePDF.GetStat() == 0)
                        {
                            num2++;
                        }
                        else
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        str = file.Replace(Path.GetExtension(file), ".pdf");
                        oGdPicturePDF.SaveToFile(file.Replace(Path.GetExtension(file), ".pdf"));
                        if (oGdPicturePDF.GetStat() != 0)
                        {
                        }
                    }
                    oGdPicturePDF.CloseDocument();
                    oGdPictureImaging.ReleaseGdPictureImage(num);
                }
                else
                {
                    oGdPicturePDF.AddImageFromGdPictureImage(num, false, true);
                    if (oGdPicturePDF.GetStat() == 0)
                    {
                        str = file.Replace(Path.GetExtension(file), ".pdf");
                        if (oGdPicturePDF.SaveToFile(file.Replace(Path.GetExtension(file), ".pdf")) != 0)
                        {
                        }
                    }
                    oGdPicturePDF.CloseDocument();
                    oGdPictureImaging.ReleaseGdPictureImage(num);
                }
            }
            File.Delete(file);
            return(str);
        }
Exemple #3
0
        /// <summary>
        /// Converts to jpeg.
        /// </summary>
        /// <param name="outputPath">The output path.</param>
        public void ConvertToJpeg(string outputPath)
        {
            GdPictureImaging image = new GdPictureImaging();
            int imageId            = image.CreateGdPictureImageFromFile(ImagePath);

            image.SaveAsJPEG(imageId, outputPath);
            image.ReleaseGdPictureImage(imageId);
            GC.Collect();
        }
Exemple #4
0
        /// <summary>
        /// Save page to jpeg file
        /// </summary>
        /// <param name="sourceFilePath">The source file path.</param>
        /// <param name="outputPath">The output path.</param>
        /// <param name="pageNumber">Page number</param>
        public void SavePageToJpeg(string sourceFilePath, string outputPath, int pageNumber)
        {
            using (GdPictureImaging image = new GdPictureImaging())
            {
                int imageId = image.CreateGdPictureImageFromFile(sourceFilePath);
                image.SelectPage(imageId, pageNumber);
                image.SaveAsJPEG(imageId, outputPath);
                image.ReleaseGdPictureImage(imageId);
            }

            GC.Collect();
        }
Exemple #5
0
        /// <summary>
        /// Gets total pages number in file
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public int GetTotalPages(string filePath)
        {
            int totalPages = 0;

            using (GdPictureImaging image = new GdPictureImaging())
            {
                int imageId = image.CreateGdPictureImageFromFile(filePath);
                totalPages = image.TiffGetPageCount(imageId);
                totalPages = totalPages > 0 ? totalPages : 1;
            }

            return(totalPages);
        }
Exemple #6
0
        /// <summary>
        /// Creates the thumbnail.
        /// </summary>
        /// <param name="outputPath">The output path.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public void CreateThumbnail(string outputPath, int width, int height)
        {
            GdPictureImaging image = new GdPictureImaging();
            int imageId            = image.CreateGdPictureImageFromFile(ImagePath);

            if (imageId > 0)
            {
                int thumbnailId = image.CreateThumbnailHQ(imageId, width, height, Color.Black);
                image.SaveAsJPEG(thumbnailId, outputPath);
                image.ReleaseGdPictureImage(imageId);
            }

            GarbageCollector.Collect();
        }
Exemple #7
0
        /// <summary>
        /// Convert the provided TIFF to a PDF, including conversion of the annotations.
        /// </summary>
        /// <param name="strOutputFilePath">The path to the Pdf.</param>
        /// <param name="errorMessage">Used to retrieve an error message.</param>
        /// <param name="strInputFilePath">The path to the tiff.</param>
        /// <param name="textExtension">The extension for the text file.</param>
        /// <returns>true if the conversion succeded otherwise returns false.</returns>
        public static bool Convert(string strOutputFilePath, ref string errorMessage, string strInputFilePath,
                                   string textExtension = "")
        {
            using (GdPictureImaging gdPictureImaging = new GdPictureImaging())
            {
                // Load the image

                int imageId = gdPictureImaging.CreateGdPictureImageFromFile(strInputFilePath);
                if (imageId == 0)
                {
                    errorMessage = System.Convert.ToString(gdPictureImaging.GetStat().ToString());
                    gdPictureImaging.ReleaseGdPictureImage(imageId);
                    return(false);
                }

                int pageCount = gdPictureImaging.GetPageCount(imageId);

                // Collect the information required for the conversion of the annotations

                PageInfo[] pageInfo = ReadPageInfo(gdPictureImaging, imageId, pageCount);

                using (MemoryStream stream = new MemoryStream())
                {
                    // Convert to Pdf in a stream

                    if (!ConvertToPdf(stream, ref errorMessage, gdPictureImaging, imageId, pageCount))
                    {
                        gdPictureImaging.ReleaseGdPictureImage(imageId);
                        return(false);
                    }

                    gdPictureImaging.ReleaseGdPictureImage(imageId);

                    // Writes the annotations to the pdf

                    if (
                        !WriteAnnotations(strOutputFilePath, ref errorMessage, stream, pageCount, pageInfo,
                                          textExtension))
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
Exemple #8
0
        public static void CleHole(List <string> strfile)
        {
            LicenseManager oLicenceManager = new LicenseManager();

            oLicenceManager.RegisterKEY(T_ConFigure.Imgid);
            int imageId = 0;

            try {
                using (GdPictureImaging oGdPictureImaging = new GdPictureImaging()) {
                    for (int i = 0; i < strfile.Count; i++)
                    {
                        string file = strfile[i];
                        imageId = oGdPictureImaging.CreateGdPictureImageFromFile(file);
                        if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
                        {
                            continue;
                        }
                        else
                        {
                            GdPictureStatus status = oGdPictureImaging.RemoveHolePunch(imageId, HolePunchMargins.MarginAll);
                            if (status != GdPictureStatus.OK)
                            {
                                continue;
                            }
                            else
                            {
                                string path = Path.Combine(Path.GetDirectoryName(file));
                                if (!Directory.Exists(path))
                                {
                                    Directory.CreateDirectory(path);
                                }
                                status = oGdPictureImaging.SaveAsTIFF(imageId, file, TiffCompression.TiffCompressionJPEG);
                                if (status != GdPictureStatus.OK)
                                {
                                    continue;
                                }
                            }
                        }
                    }
                    oGdPictureImaging.ReleaseGdPictureImage(imageId);
                }
            } catch {}
        }
        /// <summary>
        /// Convert the provided Wang annotated TIFF to a GdPicture/XMP annotated TIFF.
        /// </summary>
        /// <param name="strOutputFilePath">The path to the output tiff.</param>
        /// <param name="errorMessage">Used to retrieve an error message.</param>
        /// <param name="strInputFilePath">The path to the input tiff.</param>
        /// <param name="textExtension">The extension for the text file.</param>
        /// <returns>true if the conversion succeded otherwise returns false.</returns>
        public static bool Convert(string strOutputFilePath, ref string errorMessage, string strInputFilePath,
                                   string textExtension = "")
        {
            using (GdPictureImaging gdPictureImaging = new GdPictureImaging())
            {
                // Load the image
                int imageId = gdPictureImaging.CreateGdPictureImageFromFile(strInputFilePath);
                if (imageId == 0)
                {
                    errorMessage = System.Convert.ToString(gdPictureImaging.GetStat().ToString());
                    gdPictureImaging.ReleaseGdPictureImage(imageId);
                    return(false);
                }

                int pageCount = gdPictureImaging.GetPageCount(imageId);

                // Collect the information required for the conversion of the annotations

                PageInfo[] pageInfo = ReadPageInfo(gdPictureImaging, imageId, pageCount);

                // Save tiff to output file
                GdPictureStatus status = pageCount > 1
                    ? gdPictureImaging.TiffSaveMultiPageToFile(imageId, strOutputFilePath,
                                                               TiffCompression.TiffCompressionAUTO, 100)
                    : gdPictureImaging.SaveAsTIFF(imageId, strOutputFilePath, false,
                                                  TiffCompression.TiffCompressionAUTO, 100);

                gdPictureImaging.ReleaseGdPictureImage(imageId);

                if (status != GdPictureStatus.OK)
                {
                    return(false);
                }

                // Writes the annotations to the tiff
                return(WriteAnnotations(strOutputFilePath, ref errorMessage, pageInfo, pageCount, textExtension));
            }
        }
        public static string castTopdf(string file, GdPictureImaging oGdPictureImaging, GdPicturePDF oGdPicturePDF, bool pdfa = true, string idioma = "por", string white = null, string titulo = null, string autor = null, string assunto = null, string palavrasChaves = null, string criador = null, int dpi = 250)
        {
            try
            {
                var exFile = Path.GetExtension(file).ToUpper();
                switch (exFile)
                {
                case ".PDF":
                    #region PDF

                    String folderpdf = Guid.NewGuid().ToString();

                    string strpdf = "";

                    GdPictureStatus status = oGdPicturePDF.LoadFromFile(file, false);


                    if (status == GdPictureStatus.OK)
                    {
                        int      ident      = 1;
                        int      num1       = oGdPicturePDF.GetPageCount();
                        int      num4       = 1;
                        string[] mergeArray = new string[num1];
                        Directory.CreateDirectory(folderpdf);
                        if (num1 > 0)
                        {
                            bool flagpdf = true;

                            while (num4 <= num1)
                            {
                                oGdPicturePDF.SelectPage(num4);

                                int numpdf1 = oGdPicturePDF.RenderPageToGdPictureImage(300, true);

                                var docuemntoId = Guid.NewGuid();

                                string sstr = string.Concat(Ocr.GetCurrentDirectory(), "\\GdPicture\\Idiomas");

                                oGdPicturePDF.SaveToFile(folderpdf + @"\" + ident + "_" + docuemntoId + ".pdf");


                                var id = oGdPictureImaging.PdfOCRStart(folderpdf + @"\" + ident + "_" + docuemntoId + ".pdf", true, "", "", "", "", "");

                                oGdPictureImaging.PdfAddGdPictureImageToPdfOCR(id, numpdf1, "por", sstr, "");
                                oGdPictureImaging.PdfOCRStop(id);


                                mergeArray[num4 - 1] = folderpdf + @"\" + ident + "_" + docuemntoId + ".pdf";


                                if (oGdPicturePDF.GetStat() == 0)
                                {
                                    num4++;
                                    ident++;
                                }
                                else
                                {
                                    flagpdf = false;
                                    break;
                                }

                                oGdPictureImaging.ReleaseGdPictureImage(numpdf1);
                            }
                            oGdPicturePDF.CloseDocument();


                            if (flagpdf)
                            {
                                var strPdf1 = file.Replace(Path.GetExtension(file), ".pdf");
                                oGdPicturePDF.MergeDocuments(mergeArray, strPdf1);
                                strpdf = strPdf1;
                                oGdPicturePDF.CloseDocument();
                            }

                            oGdPictureImaging.ClearGdPicture();

                            string str1pdf = ConfigurationManager.AppSettings["PastaDestinoTemp"].ToString();
                            if (File.Exists(str1pdf + @"\" + Path.GetFileName(strpdf)))
                            {
                                File.Replace(strpdf, str1pdf + @"\" + Path.GetFileName(strpdf), null);
                            }
                            else
                            {
                                File.Move(strpdf, str1pdf + @"\" + Path.GetFileName(strpdf));
                            }

                            var filefinal = str1pdf + @"\" + Path.GetFileName(strpdf);
                            foreach (var item in Directory.GetFiles(folderpdf))
                            {
                                File.Delete(item);
                            }
                            Directory.Delete(folderpdf);
                            file = filefinal;
                        }
                        else
                        {
                            oGdPicturePDF.SelectPage(num4);
                            int    numpdf      = oGdPicturePDF.RenderPageToGdPictureImage(300, true);
                            var    docuemntoId = Guid.NewGuid();
                            string sstr        = string.Concat(Ocr.GetCurrentDirectory(), "\\GdPicture\\Idiomas");
                            oGdPictureImaging.SaveAsPDFOCR(numpdf, folderpdf + @"\" + docuemntoId + ".pdf", idioma, sstr, white, pdfa, titulo, autor, assunto, palavrasChaves, criador);


                            var strPdf = file.Replace(Path.GetExtension(file), ".pdf");
                            oGdPictureImaging.ReleaseGdPictureImage(numpdf);



                            oGdPicturePDF.MergeDocuments(System.IO.Directory.GetFiles(folderpdf), strPdf);
                            strpdf = strPdf;

                            oGdPictureImaging.ClearGdPicture();


                            string str1tif = ConfigurationManager.AppSettings["PastaDestinoTemp"].ToString();
                            if (File.Exists(str1tif + @"\" + Path.GetFileName(strpdf)))
                            {
                                File.Replace(strpdf, str1tif + @"\" + Path.GetFileName(strpdf), null);
                            }
                            else
                            {
                                File.Move(strpdf, str1tif + @"\" + Path.GetFileName(strpdf));
                            }

                            var filefinal = str1tif + @"\" + Path.GetFileName(strpdf);
                            foreach (var item in Directory.GetFiles(folderpdf))
                            {
                                File.Delete(item);
                            }
                            Directory.Delete(folderpdf);
                            file = filefinal;
                        }
                    }

                    #endregion
                    break;

                case (".TIF"):
                    String folder = Guid.NewGuid().ToString();

                    string str = "";
                    oGdPictureImaging.TiffOpenMultiPageForWrite(false);
                    int num = oGdPictureImaging.CreateGdPictureImageFromFile(file);
                    if (num != 0)
                    {
                        int ident = 1;
                        Directory.CreateDirectory(folder);

                        if (oGdPictureImaging.TiffIsMultiPage(num))
                        {
                            int      num1       = oGdPictureImaging.TiffGetPageCount(num);
                            bool     flag       = true;
                            int      num4       = 1;
                            string[] mergeArray = new string[num1];
                            while (num4 <= num1)
                            {
                                oGdPictureImaging.TiffSelectPage(num, num4);
                                // oGdPicturePDF.AddImageFromGdPictureImage(num, false, true);
                                oGdPicturePDF.NewPDF();
                                var docuemntoId = Guid.NewGuid();
                                oGdPicturePDF.SaveToFile(folder + @"\" + ident + "_" + docuemntoId + ".pdf");
                                var id = oGdPictureImaging.PdfOCRStart(folder + @"\" + ident + "_" + docuemntoId + ".pdf", true, "", "", "", "", "");

                                string sstr = string.Concat(Ocr.GetCurrentDirectory(), "\\GdPicture\\Idiomas");
                                oGdPictureImaging.PdfAddGdPictureImageToPdfOCR(id, num, "por", sstr, "");
                                oGdPictureImaging.PdfOCRStop(id);
                                //     oGdPictureImaging.SaveAsPDFOCR(num4, @"C:\Processamento" + @"\" + docuemntoId + ".pdf", idioma, sstr, "", true, titulo, autor, assunto, palavrasChaves, criador);

                                oGdPicturePDF.CloseDocument();
                                mergeArray[num4 - 1] = folder + @"\" + ident + "_" + docuemntoId + ".pdf";
                                if (oGdPicturePDF.GetStat() == 0)
                                {
                                    num4++;
                                    ident++;
                                }
                                else
                                {
                                    flag = false;
                                    break;
                                }
                                //      oGdPictureImaging.ReleaseGdPictureImage(num);
                            }


                            if (flag)
                            {
                                var strPdf = file.Replace(Path.GetExtension(file), ".pdf");

                                oGdPicturePDF.MergeDocuments(mergeArray, strPdf);
                                str = strPdf;
                            }

                            oGdPictureImaging.ReleaseGdPictureImage(num);
                            oGdPictureImaging.ClearGdPicture();

                            string str1tif = ConfigurationManager.AppSettings["PastaDestinoTemp"].ToString();
                            if (File.Exists(str1tif + @"\" + Path.GetFileName(str)))
                            {
                                File.Replace(str, str1tif + @"\" + Path.GetFileName(str), null);
                                File.Delete(file);
                            }
                            else
                            {
                                File.Move(str, str1tif + @"\" + Path.GetFileName(str));
                                File.Delete(file);
                            }

                            var filefinal = str1tif + @"\" + Path.GetFileName(str);
                            foreach (var item in Directory.GetFiles(folder))
                            {
                                File.Delete(item);
                            }
                            Directory.Delete(folder);
                            file = filefinal;
                        }
                        else
                        {
                            var    docuemntoId = Guid.NewGuid();
                            string sstr        = string.Concat(Ocr.GetCurrentDirectory(), "\\GdPicture\\Idiomas");

                            oGdPicturePDF.NewPDF();
                            oGdPicturePDF.SaveToFile(folder + @"\" + ident + "_" + docuemntoId + ".pdf");
                            var id = oGdPictureImaging.PdfOCRStart(folder + @"\" + ident + "_" + docuemntoId + ".pdf", true, "", "", "", "", "");
                            oGdPictureImaging.PdfAddGdPictureImageToPdfOCR(id, num, "por", sstr, "");
                            oGdPictureImaging.PdfOCRStop(id);
                            oGdPicturePDF.CloseDocument();

                            //oGdPictureImaging.SaveAsPDFOCR(num, folder + @"\" + docuemntoId + ".pdf", idioma, sstr, white, pdfa, titulo, autor, assunto, palavrasChaves, criador);


                            var strPdf = file.Replace(Path.GetExtension(file), ".pdf");

                            oGdPicturePDF.MergeDocuments(System.IO.Directory.GetFiles(folder), strPdf);

                            str = strPdf;

                            oGdPictureImaging.ReleaseGdPictureImage(num);
                            oGdPicturePDF.CloseDocument();

                            oGdPictureImaging.ClearGdPicture();
                            string str1tif = ConfigurationManager.AppSettings["PastaDestinoTemp"].ToString();
                            if (File.Exists(str1tif + @"\" + Path.GetFileName(str)))
                            {
                                File.Replace(str, str1tif + @"\" + Path.GetFileName(str), null);
                                File.Delete(file);
                            }
                            else
                            {
                                File.Move(str, str1tif + @"\" + Path.GetFileName(str));
                                File.Delete(file);
                            }

                            var filefinal = str1tif + @"\" + Path.GetFileName(str);
                            foreach (var item in Directory.GetFiles(folder))
                            {
                                File.Delete(item);
                            }
                            Directory.Delete(folder);
                            file = filefinal;
                        }
                    }

                    break;

                case ".TIFF":
                    String folder2 = Guid.NewGuid().ToString();

                    string str2 = "";
                    oGdPictureImaging.TiffOpenMultiPageForWrite(false);
                    int num2 = oGdPictureImaging.CreateGdPictureImageFromFile(file);
                    if (num2 != 0)
                    {
                        int ident = 1;

                        Directory.CreateDirectory(folder2);
                        if (oGdPictureImaging.TiffIsMultiPage(num2))
                        {
                            int      num1       = oGdPictureImaging.TiffGetPageCount(num2);
                            bool     flag       = true;
                            int      num3       = 1;
                            string[] mergeArray = new string[num1];
                            while (num3 <= num1)
                            {
                                oGdPictureImaging.TiffSelectPage(num2, num3);
                                oGdPicturePDF.NewPDF();
                                oGdPicturePDF.AddImageFromGdPictureImage(num2, false, true);

                                var docuemntoId = Guid.NewGuid();
                                // oGdPicturePDF.SaveToFile(folder + @"\" + docuemntoId + ".pdf");
                                oGdPicturePDF.SaveToFile(folder2 + @"\" + ident + "_" + docuemntoId + ".pdf");
                                //   var id = oGdPictureImaging.PdfOCRStart(folder + @"\" + docuemntoId + ".pdf", true, "", "", "", "", "");
                                //oGdPictureImaging.PdfAddGdPictureImageToPdfOCR(id, num, "por", str, "");
                                string sstr = string.Concat(Ocr.GetCurrentDirectory(), "\\GdPicture\\Idiomas");

                                var id = oGdPictureImaging.PdfOCRStart(folder2 + @"\" + ident + "_" + docuemntoId + ".pdf", true, "", "", "", "", "");
                                oGdPictureImaging.PdfAddGdPictureImageToPdfOCR(id, num2, "por", sstr, "");
                                oGdPictureImaging.PdfOCRStop(id);
                                oGdPicturePDF.CloseDocument();
                                //oGdPictureImaging.SaveAsPDFOCR(num3, folder2 + @"\" + docuemntoId + ".pdf", idioma, sstr, white, pdfa, titulo, autor, assunto, palavrasChaves, criador);
                                mergeArray[num3 - 1] = folder2 + @"\" + ident + "_" + docuemntoId + ".pdf";


                                if (oGdPicturePDF.GetStat() == 0)
                                {
                                    num3++;
                                    ident++;
                                }
                                else
                                {
                                    flag = false;
                                    break;
                                }
                                //oGdPictureImaging.ReleaseGdPictureImage(num2);
                            }

                            if (flag)
                            {
                                var strPdf = file.Replace(Path.GetExtension(file), ".pdf");

                                oGdPicturePDF.MergeDocuments(mergeArray, strPdf);
                                str2 = strPdf;
                            }
                            oGdPictureImaging.ReleaseGdPictureImage(num2);


                            oGdPictureImaging.ClearGdPicture();
                            string str1tiff = ConfigurationManager.AppSettings["PastaDestinoTemp"].ToString();
                            if (File.Exists(str1tiff + @"\" + Path.GetFileName(str2)))
                            {
                                File.Replace(str2, str1tiff + @"\" + Path.GetFileName(str2), null);
                                File.Delete(file);
                            }
                            else
                            {
                                File.Move(str2, str1tiff + @"\" + Path.GetFileName(str2));
                                File.Delete(file);
                            }

                            var filefinal2 = str1tiff + @"\" + Path.GetFileName(str2);
                            foreach (var item in Directory.GetFiles(folder2))
                            {
                                File.Delete(item);
                            }
                            Directory.Delete(folder2);
                            file = filefinal2;
                        }
                        else
                        {
                            var    docuemntoId = Guid.NewGuid();
                            string sstr        = string.Concat(Ocr.GetCurrentDirectory(), "\\GdPicture\\Idiomas");

                            oGdPicturePDF.NewPDF();
                            var id = oGdPictureImaging.PdfOCRStart(folder2 + @"\" + ident + "_" + docuemntoId + ".pdf", true, "", "", "", "", "");
                            oGdPicturePDF.SaveToFile(folder2 + @"\" + ident + "_" + docuemntoId + ".pdf");
                            oGdPictureImaging.PdfAddGdPictureImageToPdfOCR(id, num2, "por", sstr, "");
                            oGdPictureImaging.PdfOCRStop(id);
                            oGdPicturePDF.CloseDocument();

                            var strPdf = file.Replace(Path.GetExtension(file), ".pdf");

                            oGdPicturePDF.MergeDocuments(System.IO.Directory.GetFiles(folder2), strPdf);

                            str2 = strPdf;

                            oGdPictureImaging.ReleaseGdPictureImage(num2);
                            oGdPicturePDF.CloseDocument();

                            oGdPictureImaging.ClearGdPicture();
                            string str1tiff = ConfigurationManager.AppSettings["PastaDestinoTemp"].ToString();
                            if (File.Exists(str1tiff + @"\" + Path.GetFileName(str2)))
                            {
                                File.Replace(str2, str1tiff + @"\" + Path.GetFileName(str2), null);
                                File.Delete(file);
                            }
                            else
                            {
                                File.Move(str2, str1tiff + @"\" + Path.GetFileName(str2));
                                File.Delete(file);
                            }
                            var filefinal2 = str1tiff + @"\" + Path.GetFileName(str2);
                            foreach (var item in Directory.GetFiles(folder2))
                            {
                                File.Delete(item);
                            }
                            Directory.Delete(folder2);
                            file = filefinal2;
                        }
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                var logpath = ConfigurationManager.AppSettings["PastaDestinoLog"].ToString();
                File.AppendAllText(logpath + @"\" + "log.txt", ex.ToString());

                //  Console.WriteLine(ex.Message);
            }

            return(file);
        }
Exemple #11
0
        static void DoRemap(string fname, string dirname)
        {
            void SaveTable(ColorMap[] table, string path)
            {
                string s = JsonConvert.SerializeObject(table, Formatting.Indented);

                File.WriteAllText(path, s);
            }

            ColorMap[] LoadTable(string path)
            {
                string s = File.ReadAllText(path);

                return(JsonConvert.DeserializeObject <ColorMap[]>(s));
            }

            ColorMap[] GetTable(string path, Color newColor)
            {
                var map = ParsePixelsMap(path);

                return(GetRemapTable(map, newColor));
            }

            void BuildTable(string name)
            {
                var converter = new ColorConverter();

                Color inColor  = (Color)converter.ConvertFromString("#613e32");
                Color outColor = (Color)converter.ConvertFromString("#947965");
                Color bkgColor = (Color)converter.ConvertFromString("#fff6d2");

                var inTable  = GetTable($".\\{name}\\in.txt", inColor);
                var outTable = GetTable($".\\{name}\\out.txt", outColor);
                var bkgTable = GetTable($".\\{name}\\bkg.txt", bkgColor);

                var table = inTable.Concat(outTable).Concat(bkgTable).ToArray();

                SaveTable(table, $".\\{name}\\{name}.txt");
            }

            BuildTable(dirname);

            //Bitmap b = new Bitmap($".\\{fname}.png");

            //Rectangle r = new Rectangle(0, 0, b.Width, b.Height);

            //Bitmap gg = b.Clone(r, PixelFormat.Format8bppIndexed);

            //gg.Save($".\\{fname}_test.png");

            return;

            using (var GdPic = new GdPictureImaging())
            {
                int id = GdPic.CreateGdPictureImageFromFile($".\\{fname}.png");

                //Color mean = Color.FromArgb()

                //double count = GdPic.CountColor(id, )

                //var lol = GdPic.ColorDetection(id, true, false, false);

                //Debug.WriteLine($"{fname} {lol}");

                //var table = LoadTable($".\\{dirname}\\{dirname}.txt");

                //GdPic.SetColorRemap(id, table);

                //GdPic.SaveAsPNG(id, $".\\{fname}_test.png");
            }
        }