Exemplo n.º 1
0
        //fully qualified path & filename
        public LT_DPI_Converter(string srcFileName, string destFileName)
        {
            RasterCodecs codecs = new RasterCodecs();

            System.IO.File.Copy(srcFileName, destFileName, true);

                //Read Original Values
                RasterImage oldimage = codecs.Load(srcFileName);

                //Change values and save a new file name
                RasterImage newimage = codecs.Load(destFileName);
                int newResolution = 300; //BR says all files need to be 300 DPI. This should probably be an enum.

                // Load the source image from disk
                newimage.XResolution = newResolution;
                newimage.YResolution = newResolution;
                SizeCommand command = new SizeCommand();
                command.Width = oldimage.Width;
                command.Height = oldimage.Height;
                command.Flags = RasterSizeFlags.Resample;
                command.Run(newimage);
                //This changes the entire image and all pages. There is no need to pageinate.

                // Save the image back to disk
                codecs.Save(newimage, destFileName, RasterImageFormat.Tif, oldimage.BitsPerPixel);

            // Clean Up
                newimage.Dispose();
                oldimage.Dispose();
                codecs.Dispose();
        }
Exemplo n.º 2
0
        private void LoadImage(bool loadDefaultImage)
        {
            RasterOpenDialogLoadFormat[] loaderFilters = new RasterOpenDialogLoadFormat[3];
            loaderFilters[0] = new RasterOpenDialogLoadFormat("Bitmap Files (*.dib;*.bmp)", "*.dib;*.bmp");
            loaderFilters[1] = new RasterOpenDialogLoadFormat("TIFF Files (*.tif)", "*.tif");
            loaderFilters[2] = new RasterOpenDialogLoadFormat("All Files (*.tif, *.bmp)", "*.tif;*.bmp");

            ImageFileLoader loader = new ImageFileLoader();

            loader.OpenDialogInitialPath = _openInitialPath;
            loader.Filters = loaderFilters;

            bool bLoaded = false;

            try
            {
                if (loadDefaultImage)
                {
                    bLoaded = loader.Load(this, DemosGlobal.ImagesFolder + @"\ET\dst_rgb_image.tif", _codecs, 1, 1);
                }
                else
                {
                    bLoaded = loader.Load(this, _codecs, true) > 0;
                }

                if (bLoaded)
                {
                    _openInitialPath = Path.GetDirectoryName(loader.FileName);
                    // Resize the image so each dimension becomes a multiple of 4. This is done because it's required by some color spaces
                    int width  = loader.Image.Width;
                    int height = loader.Image.Height;

                    width  += (width % 4 == 0) ? 0 : (4 - (width % 4));
                    height += (height % 4 == 0) ? 0 : (4 - (height % 4));

                    // If the width and the height were the same, the SizeCommand will return immediately.
                    SizeCommand sizeCommand = new SizeCommand(width, height, RasterSizeFlags.None);
                    sizeCommand.Run(loader.Image);

                    CodecsImageInfo info = _codecs.GetInformation(loader.FileName, false, 1);
                    if (info.BitsPerPixel == 24)
                    {
                        _viewer.Image = loader.Image;
                        Text          = "LEADTOOLS for .NET C# Color Conversion Demo";
                    }
                    else
                    {
                        Messager.ShowError(this, "Format not supported\nthis demo supports simple TIFF - (RGB24, CMYK, YCC and LAB) and BMP - (RGB24)");
                    }
                }
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                UpdateMyControls();
            }
        }
Exemplo n.º 3
0
        private void Resize()
        {
            string interpolation = "normal";
            int    width         = 0;
            int    height        = 0;

            #region load properties from action profile xml

            try
            {
                interpolation = xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='resize']/interpolation").InnerText.Trim();
                width         = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='resize']/width").InnerText.Trim());
                height        = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='resize']/height").InnerText.Trim());
            }
            catch
            {
            }

            #endregion load properties from action profile xml

            if (height > 0 && width > 0)
            {
                SizeCommand cmd = new SizeCommand();

                switch (interpolation)
                {
                case "resample":
                    cmd.Flags = Leadtools.RasterSizeFlags.Resample;
                    break;

                case "bicubic":
                    cmd.Flags = Leadtools.RasterSizeFlags.Bicubic;
                    break;

                case "favorblack":
                    cmd.Flags = Leadtools.RasterSizeFlags.FavorBlack;
                    break;
                }

                cmd.Height = height;
                cmd.Width  = width;

                if (imageInfo.TotalPages > 0 && imageInfo.Format == Leadtools.RasterImageFormat.Gif) // #1.0.4.0
                {
                    rasterCodecs.Options.Gif.Save.AnimationWidth  = height;
                    rasterCodecs.Options.Gif.Save.AnimationHeight = width;
                    for (int i = 1; i <= img.PageCount; i++)
                    {
                        img.Page = i;
                        cmd.Run(img);
                    }
                }
                else
                {
                    cmd.Run(img);
                }
            }
        }
Exemplo n.º 4
0
        public void HasName()
        {
            var uri  = new Uri("http://demo.com");
            var mock = new Mock <IClient>();

            var sizeCommand = new SizeCommand(uri, mock.Object);

            Assert.Equal(uri, sizeCommand.Uri);
            Assert.Equal($"size '{uri}'", sizeCommand.Name);
        }
Exemplo n.º 5
0
        public async void CanGetSizeOfPage()
        {
            var uri  = new Uri("http://demo.com");
            var mock = new Mock <IClient>();

            var sizeCommand = new SizeCommand(uri, mock.Object);

            mock.Setup(c => c.GetAsync(uri, CancellationToken.None)).ReturnsAsync("12345");

            var result = await sizeCommand.RunAsync(CancellationToken.None);

            Assert.Equal($"{uri} 5", result);
        }
        public HtmlImageResizeEditor(CommandManager commandManager)
        {
            sizeCommand              = new SizeCommand(commandManager, CommandId.FormatImageAdjustWidth, CommandId.FormatImageAdjustHeight, 1, 1);
            sizeCommand.SizeChanged += new EventHandler(imageSizeControl_ImageSizeChanged);

            // This call is required by the Windows Form Designer.
            InitializeComponent();

            //mnemonics are not supported in the sidebar (since they interfere
            //with typing in the editor when displayed, or with the main menu if they
            //conflict.
            imageSizeControl.RemoveMnemonics();
        }
        private static void FillSeriesThumbnail(LoadSeriesEventArgs e, SeriesInformation seriesInfo)
        {
            if (e.LoadedSeries.Streamer.SeriesCells.Length > 0)
            {
                MedicalViewerMultiCell cell = e.LoadedSeries.Streamer.SeriesCells[0];

                if (cell.VirtualImage != null)
                {
                    if (cell.VirtualImage[cell.ActiveSubCell].ImageExist)
                    {
                        using (RasterImage image = cell.VirtualImage[cell.ActiveSubCell].Image.Clone())
                        {
                            Image thumbImage;

                            if (image.Width != 64 || image.Height != 64)
                            {
                                SizeCommand sizeCommand;


                                sizeCommand = new SizeCommand(64, 64, RasterSizeFlags.None);

                                sizeCommand.Run(image);
                            }

                            if (image.BitsPerPixel != 24)
                            {
                                ColorResolutionCommand colorRes = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace,
                                                                                             24,
                                                                                             RasterByteOrder.Bgr,
                                                                                             RasterDitheringMethod.None,
                                                                                             ColorResolutionCommandPaletteFlags.FastMatch,
                                                                                             null);


                                colorRes.Run(image);
                            }

                            thumbImage = RasterImageConverter.ConvertToImage(image, ConvertToImageOptions.InitAlpha);

                            seriesInfo.Thumbnail = thumbImage;
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void SizeWithAspect(RasterImage image)
        {
            int         newWidth;
            int         newHeight;
            SizeCommand cmd;

            if (image.Height > image.Width)
            {
                newHeight = _ThumbHeight;
                newWidth  = Convert.ToInt32(image.Width * _ThumbWidth / image.Height);
            }
            else
            {
                newWidth  = _ThumbWidth;
                newHeight = Convert.ToInt32(image.Height * _ThumbHeight / image.Width);
            }
            cmd = new SizeCommand(newWidth, newHeight, RasterSizeFlags.Resample);

            cmd.Run(image);
        }
        public void ConvertDpi(string srcFileName, string destFileName)
        {
            RasterCodecs codecs = new RasterCodecs();

            RasterImage image = codecs.Load(srcFileName);

            int newResolution = 300; //BR says all files need to be 300 DPI. This should probably be an enum.

            image.XResolution = newResolution;
            image.YResolution = newResolution;
            SizeCommand command = new SizeCommand();

            command.Width  = image.Width;
            command.Height = image.Height;
            command.Flags  = RasterSizeFlags.Resample;
            command.Run(image);

            codecs.Save(image, destFileName, RasterImageFormat.Tif, image.BitsPerPixel);

            image.Dispose();
            codecs.Dispose();
        }
Exemplo n.º 10
0
        //fully qualified path & filename
        public LT11_DPI_Transformer(string srcFileName, string destFileName)
        {
            RasterCodecs codecs = new RasterCodecs();

            //Read Original Values
            IRasterImage image = codecs.Load(srcFileName);

            //Change values and save a new file name

            int newResolution = 300; //BR says all files need to be 300 DPI. This should probably be an enum, db table or config file.

            // Load the source image from disk
            image.XResolution = newResolution;
            image.YResolution = newResolution;
            SizeCommand command = new SizeCommand();
            command.Width = image.Width;
            command.Height = image.Height;
            command.Flags = RasterSizeFlags.Resample;
            command.Run(image);
            //This changes the entire image and all pages. There is no need to pageinate.

            codecs.Save(image, destFileName, RasterImageFormat.Tif, image.BitsPerPixel);
            image.Dispose();
        }
Exemplo n.º 11
0
        ///------------------------------------------------------------------------------
        /// <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);
        }
Exemplo n.º 12
0
        ///------------------------------------------------------------------------------
        /// <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);
        }
Exemplo n.º 13
0
        // Optionally resizes the image before saving it (always preserving the original aspect ratio)
        public static void ResizeImage(RasterImage image, int width, int height)
        {
            SizeCommand sizeCommand;
            int         resizeWidth;
            int         resizeHeight;

            RasterSizeFlags flags = RasterSizeFlags.Resample;

            if (image.BitsPerPixel == 1)
            {
                flags |= RasterSizeFlags.FavorBlack;
            }

            // First check if its a FAX image (with different resolution), if so, resize it too
            if (image.XResolution != 0 && image.YResolution != 0 && Math.Abs(image.XResolution - image.YResolution) > 2)
            {
                // Yes
                if (image.XResolution > image.YResolution)
                {
                    resizeWidth  = image.ImageWidth;
                    resizeHeight = (int)((double)image.ImageHeight * (double)image.XResolution / (double)image.YResolution);
                }
                else
                {
                    resizeHeight = image.ImageHeight;
                    resizeWidth  = (int)((double)image.ImageWidth * (double)image.YResolution / (double)image.XResolution);
                }

                sizeCommand = new SizeCommand(resizeWidth, resizeHeight, flags);
                sizeCommand.Run(image);

                image.XResolution = Math.Max(image.XResolution, image.YResolution);
                image.YResolution = image.XResolution;
            }

            // Check user resize options, and resize only if needed
            if ((width == 0 && height == 0) ||
                (image.ImageWidth <= width && image.ImageHeight <= height))
            {
                return;
            }

            resizeWidth  = width;
            resizeHeight = height;

            // If width or height is 0, means the other is a fixed value and the missing value must be calculated
            // saving the aspect ratio
            if (resizeHeight == 0)
            {
                resizeHeight = (int)((double)image.ImageHeight * (double)resizeWidth / (double)image.ImageWidth + 0.5);
            }
            else if (resizeWidth == 0)
            {
                resizeWidth = (int)((double)image.ImageWidth * (double)resizeHeight / (double)image.ImageHeight + 0.5);
            }

            // Calculate the destination size
            LeadRect rc = new LeadRect(0, 0, resizeWidth, resizeHeight);

            rc = RasterImage.CalculatePaintModeRectangle(
                image.ImageWidth,
                image.ImageHeight,
                rc,
                RasterPaintSizeMode.Fit,
                RasterPaintAlignMode.Near,
                RasterPaintAlignMode.Near);

            image.ChangeViewPerspective(RasterViewPerspective.TopLeft);
            sizeCommand = new SizeCommand(rc.Width, rc.Height, flags);
            sizeCommand.Run(image);

            // Note, if the image was 1BPP, ScaleToGray converts it to 8, the format of the returned image is dealt with
            // in PrepareToSave

            // Since we resized the image, the original DPI is not correct anymore
            image.XResolution = 96;
            image.YResolution = 96;
        }
Exemplo n.º 14
0
        private void Crop()
        {
            bool blnBestFit       = false;
            int  intBestFitWidth  = 0;
            int  intBestFitHeight = 0;
            int  intCropLeft      = 0;
            int  intCropRight     = 0;
            int  intCropTop       = 0;
            int  intCropBottom    = 0;
            int  intCropping      = 0;

            #region load properties from action profile xml

            try
            {
                blnBestFit       = Convert.ToBoolean(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='crop']/bestFit").InnerText.Trim());
                intBestFitWidth  = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='crop']/bestFitWidth").InnerText.Trim());
                intBestFitHeight = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='crop']/bestFitHeight").InnerText.Trim());
                intCropLeft      = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='crop']/left").InnerText.Trim());
                intCropRight     = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='crop']/right").InnerText.Trim());
                intCropTop       = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='crop']/top").InnerText.Trim());
                intCropBottom    = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='crop']/bottom").InnerText.Trim());
            }
            catch
            {
            }

            #endregion load properties from action profile xml

            CropCommand cmd  = new CropCommand();
            SizeCommand cmd1 = new SizeCommand();
            cmd1.Flags = Leadtools.RasterSizeFlags.Resample;

            if (intSetCropWidth > 0 && intSetCropHeight > 0)
            {
                // do a crop based on the input parameters
                intSetCropLeft   = Convert.ToInt32((float)intSetCropLeft * flVisualCropFactor);
                intSetCropTop    = Convert.ToInt32((float)intSetCropTop * flVisualCropFactor);
                intSetCropWidth  = Convert.ToInt32((float)intSetCropWidth * flVisualCropFactor);
                intSetCropHeight = Convert.ToInt32((float)intSetCropHeight * flVisualCropFactor);

                cmd.Rectangle = new Rectangle(intSetCropLeft, intSetCropTop, intSetCropWidth - intSetCropLeft, intSetCropHeight - intSetCropTop);
            }
            else if (blnBestFit)
            {
                // first size the image to the closer region and then crop the rest
                float flFactor         = (float)img.Width / (float)img.Height;
                int   intWidthDiff     = intBestFitWidth - img.Width;
                int   intCalcWidthDiff = intWidthDiff;
                if (intCalcWidthDiff < 0)
                {
                    intCalcWidthDiff = intCalcWidthDiff * -1;
                }

                int intHeightDiff     = intBestFitHeight - img.Height;
                int intCalcHeightDiff = intHeightDiff;
                if (intCalcHeightDiff < 0)
                {
                    intCalcHeightDiff = intCalcHeightDiff * -1;
                }

                if (intCalcHeightDiff < intCalcWidthDiff)
                {
                    // crop width
                    intCropping = (intBestFitWidth - img.Width) / 2;
                    if (intCropping < 0)
                    {
                        intCropping = intCropping * -1;
                    }
                    cmd.Rectangle = new Rectangle(intCropping, 0, intBestFitWidth, img.Height);
                }
                else
                {
                    // crop height
                    intCropping = (intBestFitHeight - img.Height) / 2;
                    if (intCropping < 0)
                    {
                        intCropping = intCropping * -1;
                    }
                    cmd.Rectangle = new Rectangle(0, intCropping, img.Width, intBestFitHeight);
                }
            }
            else
            {
                // do a crop based on the config parameters
                cmd.Rectangle = new Rectangle(intCropLeft, intCropTop, img.Width - intCropLeft - intCropRight, img.Height - intCropTop - intCropBottom);
            }

            if (imageInfo.TotalPages > 0 && imageInfo.Format == Leadtools.RasterImageFormat.Gif) // #1.0.4.0
            {
                rasterCodecs.Options.Gif.Save.AnimationWidth  = cmd.Rectangle.Height;
                rasterCodecs.Options.Gif.Save.AnimationHeight = cmd.Rectangle.Width;
                for (int i = 1; i <= img.PageCount; i++)
                {
                    img.Page = i;
                    cmd.Run(img);
                }
            }
            else
            {
                cmd.Run(img);
            }
        }
Exemplo n.º 15
0
        private void ResizeToMax()
        {
            string interpolation = "normal";
            int    maxWidth      = 0;
            int    maxHeight     = 0;
            int    resizeHeight  = 0;
            int    resizeWidth   = 0;
            float  fltRatio      = 0;

            #region load properties from action profile xml

            try
            {
                interpolation = xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='resizetomax']/interpolation").InnerText.Trim();
                maxWidth      = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='resizetomax']/maxwidth").InnerText.Trim());
                maxHeight     = Convert.ToInt32(xmlActionProfile.SelectSingleNode("//root/actionProfile[@ID='" + strActionProfile + "']/action[@ID='resizetomax']/maxheight").InnerText.Trim());
            }
            catch
            {
            }

            #endregion load properties from action profile xml

            SizeCommand cmd = new SizeCommand();
            if (maxHeight > 0 || maxWidth > 0)
            {
                switch (interpolation)
                {
                case "resample":
                    cmd.Flags = Leadtools.RasterSizeFlags.Resample;
                    break;

                case "bicubic":
                    cmd.Flags = Leadtools.RasterSizeFlags.Bicubic;
                    break;

                case "favorblack":
                    cmd.Flags = Leadtools.RasterSizeFlags.FavorBlack;
                    break;

                case "normal":
                    cmd.Flags = Leadtools.RasterSizeFlags.Resample;
                    break;
                }

                resizeHeight = img.Height;
                resizeWidth  = img.Width;

                if (maxHeight == 0)
                {
                    //The Height will be recalculated based on maxWidth
                    if (img.Width > maxWidth)
                    {
                        resizeWidth  = maxWidth;
                        fltRatio     = (float)img.Height / (float)img.Width;
                        resizeHeight = Convert.ToInt32(fltRatio * (float)maxWidth);
                    }
                }
                else if (maxWidth == 0)
                {
                    //The Width will be recalculated based on maxheight
                    if (img.Height > maxHeight)
                    {
                        resizeHeight = maxHeight;
                        fltRatio     = (float)img.Width / (float)img.Height;
                        resizeWidth  = Convert.ToInt32(fltRatio * (float)maxHeight);
                    }
                }
                else
                {
                    if (img.Height <= maxHeight && img.Width <= maxWidth)
                    {
                        //Both are smaller or equal... leave deimesions
                        resizeHeight = img.Height;
                        resizeWidth  = img.Width;
                    }
                    else if (img.Height > maxHeight && img.Width <= maxWidth)
                    {
                        // The image is higher than maxheigth but more narrow than maxwidth -->calculate width based on max height
                        resizeHeight = maxHeight;
                        fltRatio     = (float)img.Width / (float)img.Height;
                        resizeWidth  = Convert.ToInt32(fltRatio * (float)maxHeight);
                    }
                    else if (img.Width > maxWidth && img.Height <= maxHeight)
                    {
                        // The image is smaller than maxheigth but more width than maxwidth -->calculate height based on max width
                        resizeWidth  = maxWidth;
                        fltRatio     = (float)img.Height / (float)img.Width;
                        resizeHeight = Convert.ToInt32(fltRatio * (float)maxWidth);
                    }
                    else if (img.Width > maxWidth && img.Height > maxHeight && img.Width > img.Height)
                    {
                        resizeWidth  = maxWidth;
                        fltRatio     = (float)img.Height / (float)img.Width;
                        resizeHeight = Convert.ToInt32(fltRatio * (float)maxWidth);
                    }
                    else if (img.Width > maxWidth && img.Height > maxHeight && img.Width <= img.Height)
                    {
                        resizeHeight = maxHeight;
                        fltRatio     = (float)img.Width / (float)img.Height;
                        resizeWidth  = Convert.ToInt32(fltRatio * (float)maxHeight);
                    }
                }
                cmd.Height = resizeHeight;
                cmd.Width  = resizeWidth;

                if (imageInfo.TotalPages > 0 && imageInfo.Format == Leadtools.RasterImageFormat.Gif) // #1.0.4.0
                {
                    rasterCodecs.Options.Gif.Save.AnimationWidth  = resizeWidth;
                    rasterCodecs.Options.Gif.Save.AnimationHeight = resizeHeight;
                    for (int i = 1; i <= img.PageCount; i++)
                    {
                        img.Page = i;
                        cmd.Run(img);
                    }
                }
                else
                {
                    cmd.Run(img);
                }
            }
        }
Exemplo n.º 16
0
        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();
        }
Exemplo n.º 17
0
        ///------------------------------------------------------------------------------
        /// <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);
        }
        public HtmlImageResizeEditor(CommandManager commandManager)
        {
            sizeCommand = new SizeCommand(commandManager, CommandId.FormatImageAdjustWidth, CommandId.FormatImageAdjustHeight, 1, 1);
            sizeCommand.SizeChanged += new EventHandler(imageSizeControl_ImageSizeChanged);

            // This call is required by the Windows Form Designer.
            InitializeComponent();

            //mnemonics are not supported in the sidebar (since they interfere
            //with typing in the editor when displayed, or with the main menu if they
            //conflict.
            imageSizeControl.RemoveMnemonics();
        }
Exemplo n.º 19
0
        /// <summary>
        /// マルチフレームの画像ファイルを頁ごとに分割する
        /// </summary>
        /// <param name="InPath">画像ファイルパス</param>
        private void MultiTif(int ocrSel, string InPath, string WrkPath)
        {
            //スキャン出力画像を確認
            string[] intif = System.IO.Directory.GetFiles(InPath, "*.tif");
            if (intif.Length == 0)
            {
                MessageBox.Show("OCR変換処理対象の画像ファイルが指定フォルダ " + InPath + " に存在しません", "スキャナ画像確認", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // READフォルダがなければ作成する
            string rPath = Properties.Settings.Default.PathInst + Properties.Settings.Default.PathREAD;

            if (System.IO.Directory.Exists(rPath) == false)
            {
                System.IO.Directory.CreateDirectory(rPath);
            }

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

            // FAX画像処理時にWORKフォルダがなければ作成する
            if (ocrSel == global.FAX_SELECT)
            {
                if (System.IO.Directory.Exists(WrkPath) == false)
                {
                    System.IO.Directory.CreateDirectory(WrkPath);
                }

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

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

            _pageNo = 0;
            string fnm = string.Empty;

            // 1.マルチTIFを分解して画像ファイルをREADフォルダかWorkフォルダへ保存する
            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++)
                {
                    // ファイル名(日付時間部分)
                    string fName = string.Format("{0:0000}", DateTime.Today.Year) +
                                   string.Format("{0:00}", DateTime.Today.Month) +
                                   string.Format("{0:00}", DateTime.Today.Day) +
                                   string.Format("{0:00}", DateTime.Now.Hour) +
                                   string.Format("{0:00}", DateTime.Now.Minute) +
                                   string.Format("{0:00}", DateTime.Now.Second);

                    // ファイル名設定
                    _pageNo++;

                    if (ocrSel == global.SCAN_SELECT)
                    {
                        fnm = rPath + fName + string.Format("{0:000}", _pageNo) + ".tif";   // SCANのときREADフォルダへ出力
                    }
                    else
                    {
                        fnm = WrkPath + fName + string.Format("{0:000}", _pageNo) + ".tif";     // スキャナのときWORKフォルダへ出力
                    }
                    // 画像保存
                    cs.Save(leadImg, fnm, RasterImageFormat.CcittGroup4, 0, i, i, 1, CodecsSavePageMode.Insert);
                }
            }

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

            // 3.FAX画像解像度の調整
            if (_OcrSel == global.FAX_SELECT)
            {
                foreach (string files in System.IO.Directory.GetFiles(WrkPath, "*.tif"))
                {
                    ////// 描画時に使用される速度、品質、およびスタイルを制御します。
                    ////RasterPaintProperties prop = new RasterPaintProperties();
                    ////prop = RasterPaintProperties.Default;
                    ////prop.PaintDisplayMode = RasterPaintDisplayModeFlags.Resample;
                    ////leadImg.PaintProperties = prop;

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

                    // 画像リサイズ(DPI:X:200,Y:200)
                    ResizeCommand rs = new ResizeCommand();
                    rs.DestinationImage             = leadImg;
                    rs.DestinationImage.XResolution = 200;
                    rs.DestinationImage.YResolution = 200;
                    rs.Flags = RasterSizeFlags.None;
                    rs.Run(leadImg);

                    // A4サイズへ変更
                    Leadtools.ImageProcessing.SizeCommand sz = new SizeCommand();
                    sz.Width  = 1693;
                    sz.Height = 2338;
                    sz.Run(leadImg);

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

                // 変換済みtif画像をREADフォルダへ移動する
                foreach (string files in System.IO.Directory.GetFiles(WrkPath, "*.tif"))
                {
                    System.IO.File.Move(files, rPath + "\\" + System.IO.Path.GetFileName(files));
                }
            }
        }
Exemplo n.º 20
0
        private void _btnOK_Click(object sender, EventArgs e)
        {
            if (radioResize.Checked)
            {
                if (_txtWidth.Value < 32)
                {
                    if (_width > 32)
                    {
                        MessageBox.Show("Width is too small, Must be at least 32");
                        return;
                    }
                }

                if (_txtHeight.Value < 32)
                {
                    if (_height > 32)
                    {
                        MessageBox.Show("Height is too small, Must be at least 32");
                        return;
                    }
                }


                int              i;
                SizeCommand      sizeCommand = new SizeCommand(_txtWidth.Value, _txtHeight.Value, RasterSizeFlags.Resample);
                GrayscaleCommand grayCommand = new GrayscaleCommand(8);
                int              oldWidth    = _image.Width;
                int              oldHeight   = _image.Height;
                for (i = 1; i <= _image.PageCount; i++)
                {
                    _image.Page = i;
                    grayCommand.Run(_image);
                    sizeCommand.Run(_image);
                }

                _object.VoxelSpacing = new Medical3DPoint(_object.VoxelSpacing.X * oldWidth / _txtWidth.Value, _object.VoxelSpacing.Y * oldHeight / _txtHeight.Value, _object.VoxelSpacing.Z);
            }
            else
            {
                if (Math.Abs(_txtCropWidthTo.Value - _txtCropWidthFrom.Value) < 32)
                {
                    if (_width > 32)
                    {
                        MessageBox.Show("Width is too small, Must be at least 32");
                        return;
                    }
                }

                if (_txtHeight.Value < 32)
                {
                    if (_height > 32)
                    {
                        MessageBox.Show("Height is too small, Must be at least 32");
                        return;
                    }
                }

                if (Math.Abs(_txtCropHeightTo.Value - _txtCropHeightFrom.Value) < 32)
                {
                    MessageBox.Show("Height is too small, Must be at least 32");
                    return;
                }

                int              i;
                CropCommand      cropCommand = new CropCommand(new Rectangle(_txtCropWidthFrom.Value, _txtCropHeightFrom.Value, _txtCropWidthTo.Value - _txtCropWidthFrom.Value, _txtCropHeightTo.Value - _txtCropHeightFrom.Value));
                GrayscaleCommand grayCommand = new GrayscaleCommand(8);
                for (i = 1; i <= _image.PageCount; i++)
                {
                    _image.Page = i;
                    grayCommand.Run(_image);
                    cropCommand.Run(_image);
                }

                _object.FirstPosition = new Medical3DPoint(_object.FirstPosition.X + _object.ImageOrientation[0] * _txtCropWidthFrom.Value + _object.ImageOrientation[3] * _txtCropHeightFrom.Value,
                                                           _object.FirstPosition.Y + _object.ImageOrientation[1] * _txtCropWidthFrom.Value + _object.ImageOrientation[4] * _txtCropHeightFrom.Value,
                                                           _object.FirstPosition.Z + _object.ImageOrientation[2] * _txtCropWidthFrom.Value + _object.ImageOrientation[5] * _txtCropHeightFrom.Value);

                _object.SecondPosition = new Medical3DPoint(_object.SecondPosition.X + _object.ImageOrientation[0] * _txtCropWidthFrom.Value + _object.ImageOrientation[3] * _txtCropHeightFrom.Value,
                                                            _object.SecondPosition.Y + _object.ImageOrientation[1] * _txtCropWidthFrom.Value + _object.ImageOrientation[4] * _txtCropHeightFrom.Value,
                                                            _object.SecondPosition.Z + _object.ImageOrientation[2] * _txtCropWidthFrom.Value + _object.ImageOrientation[5] * _txtCropHeightFrom.Value);
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }