コード例 #1
0
ファイル: frmOCR.cs プロジェクト: ymgw0867/MNBS
        private void CleanUp()
        {
            RasterCodecs.Shutdown();

            if (_twainSession != null)
            {
                try
                {
                    _twainSession.Shutdown();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
コード例 #2
0
 public void SaveStreamToJpeg(Stream sourceImage, string imageName)
 {
     try
     {
         RasterCodecs.Startup();
         rasterCodecs = new RasterCodecs();
         img          = rasterCodecs.Load(sourceImage);
         Leadtools.RasterImageFormat rif = Leadtools.RasterImageFormat.Jpeg;
         rasterCodecs.Save(img, imageName, rif, img.BitsPerPixel);
     }
     finally
     {
         img.Dispose();
         RasterCodecs.Shutdown();
     }
 }
コード例 #3
0
        ///----------------------------------------------------------------
        /// <summary>
        ///     伝票画像表示 </summary>
        /// <param name="iX">
        ///     現在の伝票</param>
        /// <param name="tempImgName">
        ///     画像名</param>
        ///----------------------------------------------------------------
        public void ShowImage(string tempImgName)
        {
            //string wrkFileName;

            //修正画面へ組み入れた画像フォームの表示
            //画像の出力が無い場合は、画像表示をしない。
            if (tempImgName == string.Empty)
            {
                leadImg.Visible = false;
                //global.pblImageFile = string.Empty;
                return;
            }

            //画像ファイルがあるときのみ表示
            //wrkFileName = tempImgName;
            if (System.IO.File.Exists(tempImgName))
            {
                leadImg.Visible = true;

                //画像ロード
                RasterCodecs.Startup();
                RasterCodecs cs = new RasterCodecs();

                // 描画時に使用される速度、品質、およびスタイルを制御します。
                RasterPaintProperties prop = new RasterPaintProperties();
                prop = RasterPaintProperties.Default;
                prop.PaintDisplayMode   = RasterPaintDisplayModeFlags.Resample;
                leadImg.PaintProperties = prop;

                leadImg.Image = cs.Load(tempImgName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

                //画像表示倍率設定
                if (gl.miMdlZoomRate == 0f)
                {
                    if (leadImg.ImageDpiX == 200)
                    {
                        leadImg.ScaleFactor *= gl.ZOOM_RATE;    // 200*200 画像のとき
                    }
                    else
                    {
                        leadImg.ScaleFactor *= gl.ZOOM_RATE;        // 300*300 画像のとき
                    }
                }
                else
                {
                    leadImg.ScaleFactor *= gl.miMdlZoomRate;
                }

                //画像のマウスによる移動を可能とする
                leadImg.InteractiveMode = RasterViewerInteractiveMode.Pan;

                ////右へ90°回転させる
                //RotateCommand rc = new RotateCommand();
                //rc.Angle = 90 * 100;
                //rc.FillColor = new RasterColor(255, 255, 255);
                ////rc.Flags = RotateCommandFlags.Bicubic;
                //rc.Flags = RotateCommandFlags.Resize;
                //rc.Run(leadImg.Image);

                // グレースケールに変換
                GrayscaleCommand grayScaleCommand = new GrayscaleCommand();
                grayScaleCommand.BitsPerPixel = 8;
                grayScaleCommand.Run(leadImg.Image);
                leadImg.Refresh();

                cs.Dispose();
                RasterCodecs.Shutdown();
                //global.pblImageFile = wrkFileName;

                // 画像操作ボタン
                btnPlus.Enabled  = true;
                btnMinus.Enabled = true;
            }
            else
            {
                //画像ファイルがないとき
                leadImg.Visible = false;
                //global.pblImageFile = string.Empty;

                // 画像操作ボタン
                btnPlus.Enabled  = false;
                btnMinus.Enabled = false;
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: ymgw0867/BLMT_OCR
        ///------------------------------------------------------------------------------
        /// <summary>
        ///     画像の解像度とサイズを変更する </summary>
        /// <param name="InPath">
        ///     画像ファイル入力パス</param>
        /// <returns>
        ///     true:分割を実施, false:分割ファイルなし</returns>
        ///------------------------------------------------------------------------------
        private bool imageResize(string InPath)
        {
            // 画像を確認
            if (System.IO.Directory.GetFiles(InPath, "*.tif").Count() == 0)
            {
                return(false);
            }

            RasterCodecs.Startup();
            RasterCodecs cs = new RasterCodecs();

            string fnm = string.Empty;

            //コマンドを準備します。(傾き・ノイズ除去・リサイズ)
            DeskewCommand    Dcommand  = new DeskewCommand();
            DespeckleCommand Dkcommand = new DespeckleCommand();
            SizeCommand      Rcommand  = new SizeCommand();

            // オーナーフォームを無効にする
            this.Enabled = false;

            //プログレスバーを表示する
            frmPrg frmP = new frmPrg();

            frmP.Owner = this;
            frmP.Show();

            int cImg = System.IO.Directory.GetFiles(InPath, "*.tif").Count();
            int cCnt = 0;

            foreach (string files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                cCnt++;

                //プログレスバー表示
                frmP.Text          = "OCR変換画像データロード中 " + cCnt.ToString() + "/" + cImg;
                frmP.progressValue = cCnt * 100 / cImg;
                frmP.ProgressStep();

                // 画像読み出す
                RasterImage leadImg = cs.Load(files, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);

                //画像補正処理 開始 ↓ ****************************
                try
                {
                    //画像の傾きを補正します。
                    Dcommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                    Dcommand.Run(leadImg);
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(i + "画像の傾き補正エラー:" + ex.Message);
                }

                //ノイズ除去
                try
                {
                    Dkcommand.Run(leadImg);
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(i + "ノイズ除去エラー:" + ex.Message);
                }

                //解像度調整(200*200dpi)
                leadImg.XResolution = 200;
                leadImg.YResolution = 200;

                //A4縦サイズに変換(ピクセル単位)
                Rcommand.Width  = 1637;
                Rcommand.Height = 2322;
                try
                {
                    Rcommand.Run(leadImg);
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(i + "解像度調整エラー:" + ex.Message);
                }

                //画像補正処理 終了↑ ****************************

                // 画像保存
                cs.Save(leadImg, files, RasterImageFormat.Tif, 0, 1, 1, 1, CodecsSavePageMode.Overwrite);
            }

            //LEADTOOLS入出力ライブラリを終了します。
            RasterCodecs.Shutdown();

            // いったんオーナーをアクティブにする
            this.Activate();

            // 進行状況ダイアログを閉じる
            frmP.Close();

            // オーナーのフォームを有効に戻す
            this.Enabled = true;

            return(true);
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: ymgw0867/BLMT_OCR
        ///------------------------------------------------------------------------------
        /// <summary>
        ///     マルチフレームの画像ファイルを頁ごとに分割する </summary>
        /// <param name="InPath">
        ///     画像ファイル入力パス</param>
        /// <param name="outPath">
        ///     分割後出力パス</param>
        /// <returns>
        ///     true:分割を実施, false:分割ファイルなし</returns>
        ///------------------------------------------------------------------------------
        private bool MultiTif(string InPath, string outPath, string fName)
        {
            //スキャン出力画像を確認
            if (System.IO.Directory.GetFiles(InPath, "*.tif").Count() == 0)
            {
                return(false);
            }

            // 出力先フォルダがなければ作成する
            if (System.IO.Directory.Exists(outPath) == false)
            {
                System.IO.Directory.CreateDirectory(outPath);
            }

            // 出力先フォルダ内の全てのファイルを削除する(通常ファイルは存在しないが例外処理などで残ってしまった場合に備えて念のため)
            foreach (string files in System.IO.Directory.GetFiles(outPath, "*"))
            {
                System.IO.File.Delete(files);
            }

            RasterCodecs.Startup();
            RasterCodecs cs = new RasterCodecs();

            int    _pageCount = 0;
            string fnm        = string.Empty;

            //コマンドを準備します。(傾き・ノイズ除去・リサイズ)
            DeskewCommand    Dcommand  = new DeskewCommand();
            DespeckleCommand Dkcommand = new DespeckleCommand();
            SizeCommand      Rcommand  = new SizeCommand();

            // オーナーフォームを無効にする
            this.Enabled = false;

            //プログレスバーを表示する
            frmPrg frmP = new frmPrg();

            frmP.Owner = this;
            frmP.Show();

            int cImg = System.IO.Directory.GetFiles(InPath, "*.tif").Count();
            int cCnt = 0;

            // マルチTIFを分解して画像ファイルをTRAYフォルダへ保存する
            foreach (string files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                cCnt++;

                //プログレスバー表示
                frmP.Text          = "OCR変換画像データロード中 " + cCnt.ToString() + "/" + cImg;
                frmP.progressValue = cCnt * 100 / cImg;
                frmP.ProgressStep();

                // 画像読み出す
                RasterImage leadImg = cs.Load(files, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);

                // 頁数を取得
                int _fd_count = leadImg.PageCount;

                // 頁ごとに読み出す
                for (int i = 1; i <= _fd_count; i++)
                {
                    //ページを移動する
                    leadImg.Page = i;

                    // ファイル名設定
                    _pageCount++;
                    fnm = outPath + fName + string.Format("{0:000}", _pageCount) + ".tif";

                    //画像補正処理 開始 ↓ ****************************
                    try
                    {
                        //画像の傾きを補正します。
                        Dcommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                        Dcommand.Run(leadImg);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(i + "画像の傾き補正エラー:" + ex.Message);
                    }

                    //ノイズ除去
                    try
                    {
                        Dkcommand.Run(leadImg);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(i + "ノイズ除去エラー:" + ex.Message);
                    }

                    //解像度調整(200*200dpi)
                    leadImg.XResolution = 200;
                    leadImg.YResolution = 200;

                    //A4縦サイズに変換(ピクセル単位)
                    Rcommand.Width  = 1637;
                    Rcommand.Height = 2322;
                    try
                    {
                        Rcommand.Run(leadImg);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(i + "解像度調整エラー:" + ex.Message);
                    }

                    //画像補正処理 終了↑ ****************************

                    // 画像保存
                    cs.Save(leadImg, fnm, RasterImageFormat.Tif, 0, i, i, 1, CodecsSavePageMode.Insert);
                }
            }

            //LEADTOOLS入出力ライブラリを終了します。
            RasterCodecs.Shutdown();

            // InPathフォルダの全てのtifファイルを削除する
            foreach (var files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                System.IO.File.Delete(files);
            }

            // いったんオーナーをアクティブにする
            this.Activate();

            // 進行状況ダイアログを閉じる
            frmP.Close();

            // オーナーのフォームを有効に戻す
            this.Enabled = true;

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Converts all the image file into one PDF file.
        /// </summary>
        /// <param name="imagePath">The collection of image files to combine.</param>
        /// <returns>True if the conversion was successful; else false.</returns>
        private bool ConvertImage(string[] imagePath)
        {
            try
            {
                // Get the unlock key
                RasterSupport.Unlock(RasterSupportType.PdfSave, _documentUnlockKey);

                // Startup the codecs
                RasterCodecs.Startup();
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    // Assign the codec options
                    codecs.Options.Jpeg.Save.QualityFactor     = _pdfDocumentQualityFactor;
                    codecs.Options.Jpeg.Save.SaveWithStamp     = false;
                    codecs.Options.Jpeg.Save.StampBitsPerPixel = 0;

                    // Set the raster image format.
                    RasterImageFormat rasterImageFormat = RasterImageFormat.RasPdfJpeg411;

                    // Set the pdf save type.
                    switch (_saveType)
                    {
                    case PdfSaveType.PdfA:
                        codecs.Options.Pdf.Save.SavePdfA = true;
                        rasterImageFormat = RasterImageFormat.RasPdfJpeg;
                        break;

                    case PdfSaveType.Pdf14:
                        codecs.Options.Pdf.Save.SavePdfv14 = true;
                        rasterImageFormat = RasterImageFormat.RasPdfJpeg411;
                        break;

                    case PdfSaveType.Pdf15:
                        codecs.Options.Pdf.Save.SavePdfv15 = true;
                        rasterImageFormat = RasterImageFormat.RasPdfJpeg422;
                        break;
                    }

                    // If the load tool resource path has been specified.
                    if (!String.IsNullOrEmpty(_leadToolResPath))
                    {
                        codecs.Options.Pdf.InitialPath = _leadToolResPath + "Lib;" + _leadToolResPath + "Fonts;" + _leadToolResPath + "Resource";
                    }

                    // For each image file found append into the PDF document.
                    for (int i = 0; i < imagePath.Length; i++)
                    {
                        // Load the image file into the image type.
                        using (System.Drawing.Image srcImage = System.Drawing.Image.FromFile(imagePath[i]))
                            using (RasterImage image = new RasterImage(srcImage))
                            {
                                if (i > 0)
                                {
                                    // Append each image file to the PDF document.
                                    codecs.Save(image, _pdfDocumentPath, rasterImageFormat, _pdfDocumentBitPerPixel, 1, 1, 1, CodecsSavePageMode.Append);
                                }
                                else
                                {
                                    // Create or overwrite the PDF document and
                                    // place to first image at the top of the PDF.
                                    codecs.Save(image, _pdfDocumentPath, rasterImageFormat, _pdfDocumentBitPerPixel, 1, 1, 1, CodecsSavePageMode.Overwrite);
                                }
                            }
                    }
                }

                // Return the result.
                return(true);
            }
            finally
            {
                // Shutdown the codecs
                RasterCodecs.Shutdown();

                // If the event has been attached, then
                // send a complete to the client.
                if (OnComplete != null)
                {
                    OnComplete(this, new EventArgs());
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Convert the current image to a PDF document.
        /// </summary>
        /// <returns>True if the conversion was successful; else false.</returns>
        private bool ConvertImage()
        {
            try
            {
                // Get the unlock key
                RasterSupport.Unlock(RasterSupportType.PdfSave, _documentUnlockKey);

                // Startup the codecs
                RasterCodecs.Startup();
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    // Load the image file into the image type.
                    using (System.Drawing.Image srcImage = System.Drawing.Image.FromFile(_imageDocumentPath))
                        using (RasterImage image = new RasterImage(srcImage))
                        {
                            codecs.Options.Jpeg.Save.QualityFactor     = _pdfDocumentQualityFactor;
                            codecs.Options.Jpeg.Save.SaveWithStamp     = false;
                            codecs.Options.Jpeg.Save.StampBitsPerPixel = 0;
                            codecs.Options.Jpeg.Save.StampWidth        = image.Width;
                            codecs.Options.Jpeg.Save.StampHeight       = image.Height;

                            // Set the raster image format.
                            RasterImageFormat rasterImageFormat = RasterImageFormat.RasPdfJpeg411;

                            // Set the pdf save type.
                            switch (_saveType)
                            {
                            case PdfSaveType.PdfA:
                                codecs.Options.Pdf.Save.SavePdfA = true;
                                rasterImageFormat = RasterImageFormat.RasPdfJpeg;
                                break;

                            case PdfSaveType.Pdf14:
                                codecs.Options.Pdf.Save.SavePdfv14 = true;
                                rasterImageFormat = RasterImageFormat.RasPdfJpeg411;
                                break;

                            case PdfSaveType.Pdf15:
                                codecs.Options.Pdf.Save.SavePdfv15 = true;
                                rasterImageFormat = RasterImageFormat.RasPdfJpeg422;
                                break;
                            }

                            // If the load tool resource path has been specified.
                            if (!String.IsNullOrEmpty(_leadToolResPath))
                            {
                                codecs.Options.Pdf.InitialPath = _leadToolResPath + "Lib;" + _leadToolResPath + "Fonts;" + _leadToolResPath + "Resource";
                            }

                            // Attempt to save the image.
                            codecs.Save(image, _pdfDocumentPath, rasterImageFormat, _pdfDocumentBitPerPixel);
                        }
                }

                return(true);
            }
            finally
            {
                // Shutdown the codecs
                RasterCodecs.Shutdown();

                // If the event has been attached, then
                // send a complete to the client.
                if (OnComplete != null)
                {
                    OnComplete(this, new EventArgs());
                }
            }
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: ymgw0867/nhbr_ocr
        ///------------------------------------------------------------------------------
        /// <summary>
        ///     マルチフレームの画像ファイルを頁ごとに分割する </summary>
        /// <param name="InPath">
        ///     画像ファイル入力パス</param>
        /// <param name="outPath">
        ///     分割後出力パス</param>
        /// <returns>
        ///     true:分割を実施, false:分割ファイルなし</returns>
        ///------------------------------------------------------------------------------
        private bool MultiTif(string InPath, string outPath, string fName)
        {
            //スキャン出力画像を確認
            if (System.IO.Directory.GetFiles(InPath, "*.tif").Count() == 0)
            {
                return(false);
            }

            // 出力先フォルダがなければ作成する
            if (System.IO.Directory.Exists(outPath) == false)
            {
                System.IO.Directory.CreateDirectory(outPath);
            }

            // 出力先フォルダ内の全てのファイルを削除する(通常ファイルは存在しないが例外処理などで残ってしまった場合に備えて念のため)
            foreach (string files in System.IO.Directory.GetFiles(outPath, "*"))
            {
                System.IO.File.Delete(files);
            }

            RasterCodecs.Startup();
            RasterCodecs cs = new RasterCodecs();

            int    _pageCount = 0;
            string fnm        = string.Empty;

            //コマンドを準備します。(傾き・ノイズ除去・リサイズ)
            DeskewCommand    Dcommand  = new DeskewCommand();
            DespeckleCommand Dkcommand = new DespeckleCommand();
            SizeCommand      Rcommand  = new SizeCommand();

            // マルチTIFを分解して画像ファイルをTRAYフォルダへ保存する
            foreach (string files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                // 画像読み出す
                RasterImage leadImg = cs.Load(files, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);

                // 頁数を取得
                int _fd_count = leadImg.PageCount;

                // 頁ごとに読み出す
                for (int i = 1; i <= _fd_count; i++)
                {
                    //ページを移動する
                    leadImg.Page = i;

                    // ファイル名設定
                    _pageCount++;
                    fnm = outPath + fName + string.Format("{0:000}", _pageCount) + ".tif";

                    // 2018/06/08 画像補正をしない
                    //画像補正処理 開始 ↓ ****************************
                    //try
                    //{
                    //    //画像の傾きを補正します。
                    //    Dcommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                    //    Dcommand.Run(leadImg);
                    //}
                    //catch// (Exception e)
                    //{
                    //}                       //ノイズ除去

                    //try
                    //{
                    //    Dkcommand.Run(leadImg);
                    //}
                    //catch// (Exception e)
                    //{
                    //}

                    ////解像度調整(200*200dpi)
                    //leadImg.XResolution = 200;
                    //leadImg.YResolution = 200;

                    ////A4縦サイズに変換(ピクセル単位)
                    //Rcommand.Width = 1637;
                    //Rcommand.Height = 2322;
                    //try
                    //{
                    //    Rcommand.Run(leadImg);
                    //}
                    //catch// (Exception e)
                    //{
                    //}

                    //画像補正処理 終了↑ ****************************

                    // 画像保存
                    cs.Save(leadImg, fnm, RasterImageFormat.Tif, 0, i, i, 1, CodecsSavePageMode.Insert);
                }
            }

            //LEADTOOLS入出力ライブラリを終了します。
            RasterCodecs.Shutdown();

            // InPathフォルダの全てのtifファイルを削除する
            foreach (var files in System.IO.Directory.GetFiles(InPath, "*.tif"))
            {
                System.IO.File.Delete(files);
            }

            return(true);
        }
コード例 #9
0
ファイル: frmXlsLoad.cs プロジェクト: ymgw0867/BLMT_OCR
        private void imgResize(string files)
        {
            RasterCodecs.Startup();
            RasterCodecs cs = new RasterCodecs();

            int    _pageCount = 0;
            string fnm        = string.Empty;

            //コマンドを準備します。(傾き・ノイズ除去・リサイズ)
            DeskewCommand    Dcommand  = new DeskewCommand();
            DespeckleCommand Dkcommand = new DespeckleCommand();
            SizeCommand      Rcommand  = new SizeCommand();

            // 画像読み出す
            RasterImage leadImg = cs.Load(files, 0, CodecsLoadByteOrder.BgrOrGray, 1, -1);

            // 頁数を取得
            int _fd_count = leadImg.PageCount;

            //// ファイル名設定
            //_pageCount++;
            //fnm = outPath + fName + string.Format("{0:000}", _pageCount) + ".tif";
            fnm = files;

            //画像補正処理 開始 ↓ ****************************
            try
            {
                //画像の傾きを補正します。
                Dcommand.Flags = DeskewCommandFlags.DeskewImage | DeskewCommandFlags.DoNotFillExposedArea;
                Dcommand.Run(leadImg);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(i + "画像の傾き補正エラー:" + ex.Message);
            }

            //ノイズ除去
            try
            {
                Dkcommand.Run(leadImg);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(i + "ノイズ除去エラー:" + ex.Message);
            }

            //解像度調整(200*200dpi)
            leadImg.XResolution = 200;
            leadImg.YResolution = 200;

            //A4縦サイズに変換(ピクセル単位)
            Rcommand.Width  = 1637;
            Rcommand.Height = 2322;
            try
            {
                Rcommand.Run(leadImg);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(i + "解像度調整エラー:" + ex.Message);
            }

            //画像補正処理 終了↑ ****************************

            // 画像保存
            //cs.Save(leadImg, fnm, RasterImageFormat.Tif, 1, 1, 1, 1, CodecsSavePageMode.Insert);
            cs.Save(leadImg, fnm, RasterImageFormat.Ccitt, 1, 1, 1, 1, CodecsSavePageMode.Insert);

            //LEADTOOLS入出力ライブラリを終了します。
            RasterCodecs.Shutdown();
        }
コード例 #10
0
        private string DoTheConvert(string sourceImage, string actionProfile, string annotate, ReturnPath retPath)
        {
            string strRetFile = "";

            strActionProfile = actionProfile;
            strAnnotate      = annotate;
            this.sourceImage = sourceImage;

            try
            {
                RasterCodecs.Startup();
                RasterSupport.Unlock(RasterSupportType.Pro, "LhwcFdF3jN");
                bool isLocked = RasterSupport.IsLocked(RasterSupportType.Pro);
                rasterCodecs = new RasterCodecs();
                imageInfo    = rasterCodecs.GetInformation(sourceImage, true);
                if (imageInfo.TotalPages > 0 && imageInfo.Format == Leadtools.RasterImageFormat.Gif)
                {
                    rasterCodecs.Options.Gif.Load.AnimationLoop    = imageInfo.Gif.AnimationLoop;
                    rasterCodecs.Options.Gif.Save.AnimationLoop    = imageInfo.Gif.AnimationLoop;
                    rasterCodecs.Options.Gif.Save.UseAnimationLoop = imageInfo.Gif.HasAnimationLoop;

                    if (imageInfo.Gif.HasAnimationBackground)
                    {
                        rasterCodecs.Options.Gif.Save.AnimationBackground = imageInfo.Gif.AnimationBackground;
                    }
                    rasterCodecs.Options.Gif.Save.UseAnimationBackground = imageInfo.Gif.HasAnimationBackground;
                    // #1.0.5.0

                    if (imageInfo.Gif.HasAnimationPalette)
                    {
                        rasterCodecs.Options.Gif.Save.SetAnimationPalette(imageInfo.Gif.GetAnimationPalette());
                    }
                    rasterCodecs.Options.Gif.Save.UseAnimationPalette = imageInfo.Gif.HasAnimationPalette;

                    rasterCodecs.Options.Gif.Save.AnimationWidth  = imageInfo.Gif.AnimationWidth;
                    rasterCodecs.Options.Gif.Save.AnimationHeight = imageInfo.Gif.AnimationHeight;
                }
                img = rasterCodecs.Load(sourceImage);

                // Load convert action profile
                if (Init(sourceImage, strActionProfile))
                {
                    // loop on actions
                    LoopActions();
                    SaveImage();

                    // add a copyright or something like this to the image
                    if (xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='annotate']") != null && strTargetImage.Length > 0)
                    {
                        Annotate();
                    }

                    if (retPath == ReturnPath.AbsPath)
                    {
                        strRetFile = strTargetImage;
                    }
                    else if (retPath == ReturnPath.Url)
                    {
                        strRetFile = strTargetImageUrl;
                    }
                }
            }

            finally
            {
                img.Dispose();
                RasterCodecs.Shutdown();
            }

            return(strRetFile);
        }
コード例 #11
0
        private void Change_Click(object sender, EventArgs e)
        {
            // Some sanity checks !
            if (txtInFile.Text.Length == 0)
            {
                MessageBox.Show("Please enter a valid input file name ");
                return;
            }

            if (!System.IO.File.Exists(txtInFile.Text))
            {
                MessageBox.Show("Please enter a valid input file name ");
                return;
            }

            if (txtOutFile.Text.Length == 0)
            {
                MessageBox.Show("Please enter a valid output file name ");
                return;
            }
            if (txtInFile.Text == txtOutFile.Text)
            {
                MessageBox.Show("Input and output file names can't be the same!");
                return;
            }

            DicomDataSetSaveFlags saveFlags = (DicomDataSetSaveFlags.MetaHeaderPresent | DicomDataSetSaveFlags.GroupLengths);

            // Get desired transfer syntax
            string uid = ((MyTransferSyntax)cmbTransferSyntax.Items[cmbTransferSyntax.SelectedIndex]).szUID;
            int    nQFactor;

            if (IsUidUsingQFactor(uid))
            {
                nQFactor = Convert.ToInt16(txtQFactor.Text);
                if ((nQFactor < 2 || nQFactor > 255) && (nQFactor != 0))
                {
                    string message = "Please enter a valid quality factor:\r\n" +
                                     "\t 0 (lossless)\r\n" +
                                     "\t 2 (lossy highest quality) to 255 (lossy most compression)";

                    MessageBox.Show(message, "Please enter a valid quality factor.");
                    return;
                }
            }
            else
            {
                nQFactor = 0;
            }
            //Load input dataset

#if !(LEADTOOLS_V17_OR_LATER)
            RasterCodecs.Startup();
#endif
            DicomEngine.Startup();
            DicomDataSet DicomDs = new DicomDataSet();
            DicomDs.Reset();
            try
            {
                DicomDs.Load(txtInFile.Text, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to load the Dataset!");
                return;
            }

            if (IsUidJpeg2000(uid))
            {
                // Setting JPEG 2000 options
                DicomDs.Jpeg2000Options = m_J2KOptions;
            }

            // Ensure that the DICOM File Meta Information is added
            CheckFileMetaInfo(DicomDs);

            //Change dataset to desired transfer syntax
            try
            {
                ChangeTransferSyntaxFlags flags = ChangeTransferSyntaxFlags.None;
#if LEADTOOLS_V175_OR_LATER
                if (checkBoxYbrFull.Checked)
                {
                    flags |= ChangeTransferSyntaxFlags.YbrFull;
                }
#endif

#if LEADTOOLS_V19_OR_LATER
                DicomDs.ChangeTransferSyntax(txtOutFile.Text, uid, nQFactor, flags, saveFlags);
#else
                DicomDs.ChangeTransferSyntax(uid, nQFactor, flags);
#endif
            }
            catch (Exception ex)
            {
                string errorString = ex.Message.ToLower();
                if (errorString.Contains("parameter"))
                {
                    const string strErr = "Failed to change dataset transfer syntax.\nPossible cause:\" Bits Allocated\" for source dataset doesn't match desired \"Transfer Syntax\".";
                    MessageBox.Show(strErr, "Failed to change dataset transfer syntax.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show(ex.Message, "LEAD Error");
                }

                return;
            }

#if !LEADTOOLS_V19_OR_LATER
            // Save dataset!
            try
            {
                DicomDs.Save(txtOutFile.Text, saveFlags);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to save dataset");
                return;
            }
#endif // #if !LEADTOOLS_V19_OR_LATER

            DicomEngine.Shutdown();

#if !LEADTOOLS_V17_OR_LATER
            RasterCodecs.Shutdown();
#endif
            MessageBox.Show("Conversion Succeeded", "SUCCESS");

            //this.Cursor = Cursors.WaitCursor;
            //this.Cursor = Cursors.Arrow;
        }