Esempio n. 1
0
        public static void MergeFiles(string mainFile, string appendFile, bool annotation)
        {
            if (MergeFilesByCopy(mainFile, appendFile))
            {
                return;
            }


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

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

            try
            {
                // load the image and annotation information for the
                // append file.
                image = codec.Load(appendFile);
                int pageCount = image.PageCount;
                if (annotation)
                {
                    tagsData = new RasterTagMetadata[pageCount];
                    for (int i = 0; i < pageCount; ++i)
                    {
                        tagsData[i] = codec.ReadTag(appendFile, i + 1, RasterTagMetadata.AnnotationTiff);
                    }
                }
                StatusForm statusForm = new StatusForm();
                statusForm.LoadFormData(appendFile, mainFile, pageCount);
                statusForm.Show();
                statusForm.Refresh();
                image2 = codec.Load(mainFile);
                int mainPageNumber = image2.PageCount;
                for (int i = 0; i < pageCount; ++i)
                {
                    codec.Save(image, mainFile, RasterImageFormat.CcittGroup4, 1, i + 1, i + 1, 1, CodecsSavePageMode.Append);
                    if (annotation)
                    {
                        if ((tagsData != null) && (tagsData[i] != null))
                        {
                            codec.WriteTag(mainFile, mainPageNumber + i + 1, tagsData[i]);
                        }
                    }
                    statusForm.ShowPageInfo(i);
                }
                statusForm.Close();
            }
            finally
            {
                if (image != null)
                {
                    image.Dispose();
                }
                if (image2 != null)
                {
                    image2.Dispose();
                }
            }
        }
        //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();
        }
Esempio n. 3
0
        public static Control CreateControl(string zoomPolicy, Font font, Size layoutSize)
        {
            switch (zoomPolicy)
            {
            case "RasterImageListZoomPolicy":
                RasterImageList imageList1 = new RasterImageList();
                imageList1.Dock = DockStyle.Fill;
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    MemoryStream stream1 = new MemoryStream();
                    Properties.Resources.Accnt.Save(stream1, ImageFormat.Png);
                    stream1.Position = 0;
                    RasterImage image1 = codecs.Load(stream1);
                    stream1.Close();

                    stream1 = new MemoryStream();
                    Properties.Resources.Bill.Save(stream1, ImageFormat.Png);
                    stream1.Position = 0;
                    RasterImage image2 = codecs.Load(stream1);
                    stream1.Close();

                    stream1 = new MemoryStream();
                    Properties.Resources.Check.Save(stream1, ImageFormat.Png);
                    stream1.Position = 0;
                    RasterImage image3 = codecs.Load(stream1);
                    stream1.Close();

                    stream1 = new MemoryStream();
                    Properties.Resources.Cust.Save(stream1, ImageFormat.Png);
                    stream1.Position = 0;
                    RasterImage image4 = codecs.Load(stream1);
                    stream1.Close();
                    imageList1.Items.Add(new RasterImageListItem(image1, 1, "aaa"));
                    imageList1.Items.Add(new RasterImageListItem(image2, 1, "bbb"));
                    imageList1.Items.Add(new RasterImageListItem(image3, 1, "ccc"));
                    imageList1.Items.Add(new RasterImageListItem(image4, 1, "ddd"));
                }
                return(imageList1);

            case "RasterImageViewerZoomPolicy":
                RasterImageViewer imageViewer1 = new RasterImageViewer();
                imageViewer1.Dock = DockStyle.Fill;
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    MemoryStream stream1 = new MemoryStream();
                    Properties.Resources.Forest.Save(stream1, ImageFormat.Png);
                    stream1.Position = 0;
                    RasterImage image1 = codecs.Load(stream1);
                    stream1.Close();
                    imageViewer1.Image = image1;
                }
                return(imageViewer1);

            default:
                break;
            }
            return(null);
        }
Esempio n. 4
0
        private void OpenImage(string path)
        {
            RasterImage image = _rasterCodecs.Load(path);

            this.Text = String.Format("{0} [{1}]", _caption, path);
            OpenImage(image);
        }
Esempio n. 5
0
        private void LoadImageList()
        {
            if (fileName == null || "".Equals(fileName))
            {
                return;
            }
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException();
            }
            RasterCodecs codec = new RasterCodecs();

            CodecsImageInfo info = codec.GetInformation(fileName, true);

            RasterPaintProperties paintProp = imageList.PaintProperties;

            paintProp.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray;

            int lastPage = info.TotalPages;

            image = codec.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, lastPage);
            imageList.Items.Clear();
            int totalCount = image.PageCount;

            for (int i = 1; i <= totalCount; ++i)
            {
                RasterImageListItem imageItem = new RasterImageListItem(image, i, "Page " + i.ToString());
                imageList.Items.Add(imageItem);
            }

            LoadCheckBox(totalCount);
        }
        private string imageFileName;                // Last file name we loaded; this is used in the "Writing Barcodes" tutorial


        private void loadImageButton_Click(object sender, EventArgs e)
        {
            string fileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Barcode1.tif";

            //Or uncomment the following to load your own file
            //using (OpenFileDialog dlg = new OpenFileDialog())
            //{
            //    if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            //    {
            //        fileName = dlg.FileName;
            //    }
            //    else
            //    {
            //        return;,
            //    }
            //}

            // Load the image
            using (RasterCodecs codecs = new RasterCodecs())
            {
                RasterImage newImage = codecs.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

                // Dispose of the image
                if (theImage != null)
                {
                    theImage.Dispose();
                }

                theImage      = newImage;
                imageFileName = fileName;
            }
        }
Esempio n. 7
0
        private void LoadFile(RasterCodecs codec)
        {

            if (fileName == null || "".Equals(fileName))
            {
                _image = null;
                return;
            }

            CodecsTiffLoadOptions options = codec.Options.Tiff.Load;

            /*
            codec.Options.Load.Compressed = true;
             */

            //    codec.Options.Load.XResolution = 204;
            //    codec.Options.Load.YResolution = 196;
            //    


            CodecsImageInfo info = codec.GetInformation(fileName, true);
            int firstPage = 1;
            int lastPage = info.TotalPages;
            _image = codec.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage);
            //codec.Options.Load.

        }
Esempio n. 8
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            // show the open file dialog
            var dlg = new OpenFileDialog {
                Filter = @"All Files|*.*"
            };

            if (dlg.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            try
            {
                // try to load the file
                rpbOriginal.Image?.Dispose();
                // set the image into the viewer
                using (var codecs = new RasterCodecs())
                {
                    rpbOriginal.Image = codecs.Load(dlg.FileName);
                }
                ProcessImage();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
        }
        protected override object LoadItem(ImageViewerItem item)
        {
            // This method is called when an item comes into view
            // and is not cached in memory

            // For this example, all we need is to load the image
            // from the original file. But we can also load other
            // state and data from a database or using deserilization.

            // In our demo, the item index is the page index
            // However, we can use the item .Tag property or derive our
            // own class to hold the data needed to load the page

            // Index is 0-based, so add 1 to get the page number
            var pageNumber = this.ImageViewer.Items.IndexOf(item) + 1;

            // Load the page and return it
            if (_useSVG)
            {
                var svgDocument = _rasterCodecs.LoadSvg(_imageFileName, pageNumber, null) as SvgDocument;

                // Ensure the SVG optimized for fast viewing
                MainForm.OptimizeForView(svgDocument);

                return(svgDocument);
            }
            else
            {
                var rasterImage = _rasterCodecs.Load(_imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, pageNumber, pageNumber);
                return(rasterImage);
            }
        }
Esempio n. 10
0
        private void LoadFile(RasterCodecs codec)
        {
            if (fileName == null || "".Equals(fileName))
            {
                _image = null;
                return;
            }

            CodecsTiffLoadOptions options = codec.Options.Tiff.Load;

            /*
             * codec.Options.Load.Compressed = true;
             */

            //    codec.Options.Load.XResolution = 204;
            //    codec.Options.Load.YResolution = 196;
            //


            CodecsImageInfo info      = codec.GetInformation(fileName, true);
            int             firstPage = 1;
            int             lastPage  = info.TotalPages;

            _image = codec.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage);
            //codec.Options.Load.
        }
Esempio n. 11
0
        private static string PreProcessAndRecognizeSmallImage(string filename)
        {
            //initialize the codes
            using (var codecs = new RasterCodecs())
                using (var img = codecs.Load(filename))
                {
                    ChangeImageResolution(img, 300);
                    //Convert to Black and white with the AutoBinarizeCommand
                    new AutoBinarizeCommand().Run(img);

                    //Convert to 1BPP
                    new ColorResolutionCommand {
                        BitsPerPixel = 1
                    }.Run(img);

                    //run the OCR process on the processed image and extract the text
                    using (var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false))
                    {
                        ocrEngine.Startup(null, null, null, null);
                        using (var ocrPage = ocrEngine.CreatePage(img, OcrImageSharingMode.None))
                        {
                            ocrPage.Recognize(null);
                            return(ocrPage.GetText(-1));
                        }
                    }
                }
        }
Esempio n. 12
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            try
            {
                using (DicomDataSet ds = new DicomDataSet())     //New data set
                {
                    if (!File.Exists(_EncapsulatedPDFDicomFile)) //Check to see if the DICOM file has already been created
                    {
                        MessageBox.Show(string.Format("File \"{0}\" doesn't exist, try clicking the \"{1}\" button first", _EncapsulatedPDFDicomFile, btnCreate.Text));
                        return;
                    }

                    ds.Load(_EncapsulatedPDFDicomFile, DicomDataSetLoadFlags.None);                        //Load the DICOM File containing the encapsulsated document
                    DicomElement element = ds.FindFirstElement(null, DicomTag.EncapsulatedDocument, true); //Find the EncapsulatedDocument element (0042:0011)
                    if (element != null)
                    {
                        DicomDataSet_GetEncapsulatedDocumentExample(element, false, ds, _PDFOutFile); //Extract and print the attributes of the encapsulated document

                        _codecs.Options.Load.XResolution = 300;
                        _codecs.Options.Load.YResolution = 300;
                        rasterImageViewer1.Image         = _codecs.Load(_PDFOutFile); //Load the encapsulated document into the image viewer
                    }
                    else
                    {
                        MessageBox.Show("Couldn't find Encapsulated Document element (0042,0011)");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 13
0
        private void LoadStream(RasterCodecs codec)
        {
            if (stream == null)
            {
                _image = null;
                return;
            }

            CodecsTiffLoadOptions options = codec.Options.Tiff.Load;

            /*
             * codec.Options.Load.Compressed = true;
             */

            //    codec.Options.Load.XResolution = 204;
            //    codec.Options.Load.YResolution = 196;
            //


            CodecsImageInfo info      = codec.GetInformation(stream, true);
            int             firstPage = 1;
            int             lastPage  = info.TotalPages;

            _image = codec.Load(stream, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage);
        }
Esempio n. 14
0
        /// <summary>
        /// Called by the main form to set a new document into the viewer
        /// </summary>
        public void SetDocument(string documentFileName, int firstPageNumber, int lastPageNumber, RasterCodecs rasterCodecsInstance)
        {
            _documentFileName     = documentFileName;
            _rasterCodecsInstance = rasterCodecsInstance;

            // Create the pages thumbnails
            _imageList.Items.Clear();
            for (int pageNumber = firstPageNumber; pageNumber <= lastPageNumber; pageNumber++)
            {
                RasterImage thumbnailImage = _rasterCodecsInstance.Load(_documentFileName, 160, 160, 0, RasterSizeFlags.Resample, CodecsLoadByteOrder.BgrOrGray, pageNumber, pageNumber);
                if (thumbnailImage != null)
                {
                    int             viewPageNumber = pageNumber - firstPageNumber + 1;
                    ImageViewerItem item           = new ImageViewerItem();
                    item.Image = thumbnailImage;
                    item.Tag   = pageNumber;
                    item.Text  = "Page " + viewPageNumber.ToString();
                    _imageList.Items.Add(item);
                }
                _imageList.Items[0].IsSelected = true;
            }

            UpdateImageInfo();
            UpdatePageInfo();
            UpdateUIState();
        }
Esempio n. 15
0
        protected override void Run()
        {
            int ticker = 0;
            int step   = (int)(100 / files.Length);

            RasterCodecs codecs = new RasterCodecs();

            for (int i = 0; i < files.Length; i++)
            {
                string file = files[i];
                Progress(ticker += step, $"Loading {file}...");

                try
                {
                    RasterImage image = codecs.Load(file);
                    image.CustomData.Add(FormName, System.IO.Path.GetFileName(file));

                    double scaleFactor = maxHeight / (double)image.ImageHeight;

                    int maxWidth = (int)(image.ImageWidth * scaleFactor);

                    RasterImage th = image.CreateThumbnail(maxWidth, maxHeight, image.BitsPerPixel, image.ViewPerspective, RasterSizeFlags.None);

                    th.CustomData.Add(OriginalImage, image);

                    OnImageLoaded(th);
                }
                catch (Exception ex)
                {
                    OnImageLoadError(file, ex.Message);
                }
            }

            base.Run();
        }
        public void ConvertTifToPdf(string SourceFileName, string DestFileName)
        {
            RasterCodecs CodecsCommand = new RasterCodecs();
            RasterImage  LeadImage     = null;

            try
            {
                UnlockLeadToolsPDFSupport();
                //RasterCodecs.CodecsPath = codecsPath;
                //CodecsCommand.Options.Pdf.InitialPath = pdfInitialPath;
                CodecsCommand.Options.Pdf.Save.UseImageResolution     = true;
                CodecsCommand.Options.Tiff.Load.IgnoreViewPerspective = true;
                LeadImage = CodecsCommand.Load(SourceFileName);
                //LeadImage.ChangeCompression((LeadImage.IsSuperCompressed == true) ? RasterCompression.None : RasterCompression.Super);
                if (String.IsNullOrEmpty(DestFileName))
                {
                    DestFileName = System.IO.Path.Combine(System.IO.Path.GetTempPath().ToString(), Guid.NewGuid().ToString() + ".PDF");
                }

                CodecsCommand.Save(LeadImage, DestFileName, Leadtools.RasterImageFormat.RasPdf, 1, 1,
                                   LeadImage.PageCount, 1, Leadtools.Codecs.CodecsSavePageMode.Overwrite);
            }
            finally
            {
                if (LeadImage != null)
                {
                    LeadImage.Dispose();
                }
                if (CodecsCommand != null)
                {
                    CodecsCommand.Dispose();
                }
            }
        }
Esempio n. 17
0
        private void LoadImageList(String fileName, RasterImageList rasterImageList) {

            if (fileName == null || "".Equals(fileName))
            {
                return;
            }
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException();
            }
            RasterCodecs codec = new RasterCodecs();

            CodecsImageInfo info = codec.GetInformation(fileName,true);

            RasterPaintProperties paintProp = rasterImageList.PaintProperties;
            paintProp.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray;

            int lastPage = info.TotalPages;
            RasterImage image =codec.Load(fileName,0,CodecsLoadByteOrder.BgrOrGray,1,lastPage);
            rasterImageList.Items.Clear();
            int totalCount = image.PageCount;
            for (int i = 1; i <= totalCount; ++i)
            {
                RasterImageListItem imageItem = new RasterImageListItem(image, i, "Page " + i.ToString());
                rasterImageList.Items.Add(imageItem);

            }

        }
Esempio n. 18
0
        public static void ExportPdfImage(string filename)
        {
            var outputFile = Path.Combine(Leadtools.Demo.Support.Path.GetOutputPath(), Path.GetFileNameWithoutExtension(filename) + "_Image.pdf");

            // Create instance of RasterCodecs object to load and save the file
            // https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.rastercodecs.html
            using (var codecs = new RasterCodecs())
            {
                // We want to load all the pages of the file
                codecs.Options.Load.AllPages = true;

                // Load the image
                // https://www.leadtools.com/help/leadtools/v19/dh/l/leadtools~leadtools.rasterimage.html
                using (var image = codecs.Load(filename))
                {
                    if (image.BitsPerPixel != 1)
                    {
                        // Use the AutoBinarize Command to convert the image to 1bpp (black and white)
                        // https://www.leadtools.com/help/leadtools/v19/dh/po/leadtools.imageprocessing.core~leadtools.imageprocessing.core.autobinarizecommand.html
                        new AutoBinarizeCommand().Run(image);
                    }
                    // Save the image out as a 1BPP CCITT Group 4 compressed PDF
                    // https://www.leadtools.com/help/leadtools/v19/dh/co/leadtools.codecs~leadtools.codecs.rastercodecs~save.html
                    codecs.Save(image, outputFile, RasterImageFormat.RasPdfG4, 1);
                }
            }
        }
Esempio n. 19
0
 public void LoadFile()
 {
     using (var codecs = new RasterCodecs())
     {
         codecs.Options.Load.Format = RasterImageFormat.Tif;
         _viewer.Image = codecs.Load(ImageFilename);
     }
 }
Esempio n. 20
0
        /// <summary>
        /// 縦、又は横を走査して指定色が所定のカウント数分連続していたらエラーとする
        /// </summary>
        /// <param name="strFile"></param>
        /// <returns></returns>
        private bool CheckCorrupt(string strFile)
        {
            int iPointX = (int)this.numPointX.Value;
            int iPointY = (int)this.numPointY.Value;

            using (var tempImage = codecs.Load(strFile))
            {
                int iCorruptCount = 0;                        // 対象色の連続カウント
                int iLimitCount   = (int)this.numPixel.Value; // 連続カウントの限界値
                // ターゲットカラー(System.Drawing.ColorをLeadtools.RasterColorに変換)
                RasterColor targetColor = RasterColorConverter.FromColor(cpTargetColor.Color);
                if (this.cmbDirection.SelectedIndex == 0)
                {
                    // 縦方向に走査
                    int iHeight = tempImage.Height;
                    for (int i = 0; i < iHeight; i++)
                    {
                        //RasterColor sourceColor = tempImage.GetPixel(i, 0);
                        if (RasterColor.Equals(targetColor, tempImage.GetPixel(i, iPointX)) == true)
                        {
                            iCorruptCount += 1;
                        }
                        else
                        {
                            iCorruptCount = 0;
                        }
                        if (iCorruptCount == iLimitCount)
                        {
                            // 限界値に達したらエラーとする
                            return(false);
                        }
                    }
                }
                else
                {
                    // 横方向に走査
                    int iWidth = tempImage.Width;
                    for (int i = 0; i < iWidth; i++)
                    {
                        //RasterColor sourceColor = tempImage.GetPixel(0, i);
                        if (RasterColor.Equals(targetColor, tempImage.GetPixel(iPointY, i)) == true)
                        {
                            iCorruptCount += 1;
                        }
                        else
                        {
                            iCorruptCount = 0;
                        }
                        if (iCorruptCount == iLimitCount)
                        {
                            // 限界値に達したらエラーとする
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
        static void Main(string[] args)
        {
            Initialize();
            var      image = codecs.Load(@"randomtext.png");
            LeadRect rect  = FindFirstZone(image);

            DoOcr(image, rect);
            Console.ReadLine();
        }
Esempio n. 22
0
        private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            UpdateStatusMessage("");
            if (e.Node == null)
            {
                return;
            }

            string fullPath = Path.Combine(_rootPath, _projectPath, e.Node.FullPath);

            if (!File.Exists(fullPath))
            {
                return;
            }

            if (rasterPictureBox1.Image != null && !rasterPictureBox1.Image.IsDisposed)
            {
                rasterPictureBox1.Image.Dispose();
            }

            try
            {
                using (var codecs = new RasterCodecs())
                {
                    rasterPictureBox1.Image = codecs.Load(fullPath);
                }
            }
            catch (Exception exception)
            {
                ClearMap(e.Node.Text);
                UpdateStatusMessage(exception.Message);
                return;
            }

            double?longitude = GpsTags.GetLongitude(fullPath);
            double?latitude  = GpsTags.GetLatitude(fullPath);

            if (!longitude.HasValue || !latitude.HasValue)
            {
                ClearMap(e.Node.Text);
                return;
            }
            labelStatusMapLink.Visible       = true;
            labelStatusStreeViewLink.Visible = true;

            UpdateStatusMessage($@"Coordinates for {e.Node.Text}: {latitude:F5}, {longitude:F5}");
            UpdateStatusMapLink(latitude.Value, longitude.Value);

            string targetHtmlFile = Path.Combine(Application.StartupPath, "map.html");

            CreateHtmlFile("MapTemplate.html", targetHtmlFile,
                           latitude.ToString(), longitude.ToString(),
                           e.Node.Name);

            webBrowser1.Url = new Uri(targetHtmlFile);
        }
Esempio n. 23
0
        public bool Load(IWin32Window owner, RasterCodecs codecs, bool autoLoad)
        {
            _fileName = string.Empty;
            _image    = null;

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < LoadFormat.Entries.Length; i++)
            {
                sb.Append(LoadFormat.Entries[i].ToString());
                if (i != (LoadFormat.Entries.Length - 1))
                {
                    sb.Append("|");
                }
            }

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter      = sb.ToString();
            ofd.FilterIndex = _filterIndex;

            bool ok = false;

            try
            {
                if (ofd.ShowDialog(owner) == DialogResult.OK)
                {
                    _fileName = ofd.FileName;
                    ok        = true;

                    _filterIndex = ofd.FilterIndex;

                    CodecsImageInfo info;

                    using (WaitCursor wait = new WaitCursor())
                        info = codecs.GetInformation(ofd.FileName, true);
                    if (autoLoad && ok)
                    {
                        using (WaitCursor wait = new WaitCursor())
                        {
                            _image = codecs.Load(ofd.FileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);
                        }
                    }
                }
                else
                {
                    ok = true;
                }
            }
            catch
            {
                MessageBox.Show("Failed to load image.\nPlease note that, you can't use this dialog to load a DICOM file as an image.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ok = false;
            }
            return(ok);
        }
Esempio n. 24
0
        public HttpResponseMessage CreateFiles(FormDataCollection Form)
        {
            HttpResponseMessage httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, "Some problem in create master form set.");

            try
            {
                if (Form != null)
                {
                    string FileName     = Form["FileName"]?.ToString().Trim() ?? "";
                    string folderName   = Form["FolderName"]?.ToString().Trim() ?? "";
                    string FriendlyName = Form["FriendlyName"]?.ToString().Trim() ?? "";

                    string workingDirectory = HttpContext.Current.Server.MapPath("~/" + RootFolderName + "/" + FriendlyName);
                    string tempDirectory    = HttpContext.Current.Server.MapPath("~/" + RootFolderName + "/temp");
                    string filePath         = tempDirectory + @"\" + FileName;

                    if (Directory.Exists(workingDirectory) && Directory.Exists(tempDirectory) && File.Exists(filePath))
                    {
                        ServiceHelper.SetLicense();
                        RasterImage scannedImage = null;
                        using (RasterCodecs _codecs = new RasterCodecs())
                        {
                            //scannedImage = _codecs.Load(filePath);

                            CodecsImageInfo info           = _codecs.GetInformation(filePath, true);
                            int             infoTotalPages = info.TotalPages;
                            scannedImage = _codecs.Load(filePath, 0, CodecsLoadByteOrder.BgrOrGray, 1, info.TotalPages);
                            DirectoryInfo directoryInfo = new DirectoryInfo(workingDirectory);
                            if (directoryInfo.GetFiles("*").ToList().Count == 0)
                            {
                                CreateMasterForms(scannedImage, workingDirectory, FriendlyName, folderName);
                                File.Delete(filePath);
                                httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, "Master form created successfully.");
                            }
                            else
                            {
                                workingRepository = new DiskMasterFormsRepository(_codecs, workingDirectory);
                                var diskMasterForm = workingRepository?.RootCategory?.MasterForms?.FirstOrDefault();
                                if (diskMasterForm != null)
                                {
                                    AddMasterFormPages(scannedImage, (DiskMasterForm)diskMasterForm, folderName);
                                }
                                File.Delete(filePath);
                                httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, "Page added to master form set successfully.");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, "Some problem in create master form set." + ex.Message.ToString());
            }
            return(httpResponseMessage);
        }
        private void UploadDownload()
        {
            try
            {
                // Set the credentials
                if (_serverProperties.UseCredentials)
                {
                    _rasterCodecs.UriOperationCredentials = new NetworkCredential(_serverProperties.UserName, _serverProperties.Password, _serverProperties.Domain);
                }
                else
                {
                    _rasterCodecs.UriOperationCredentials = CredentialCache.DefaultCredentials;
                }

                // Set the proxy
                if (_serverProperties.UseProxy)
                {
                    _rasterCodecs.UriOperationProxy = new WebProxy(_serverProperties.Host, _serverProperties.Port);
                }
                else
                {
                    _rasterCodecs.UriOperationProxy = null;
                }

                // Create the URL for the image
                string url = _serverProperties.Url;
                if (!url.EndsWith("/"))
                {
                    url += "/";
                }

                // Use the SharePoint Lists web service
                url += "Shared Documents/" + _imageFileName;

                Uri uri = new Uri(url);
                _imageServerName = uri.ToString();

                // Upload or download this image
                if (_isDownloading)
                {
                    _rasterImage = _rasterCodecs.Load(uri);
                }
                else
                {
                    _rasterCodecs.Save(_rasterImage, uri, _rasterImage.OriginalFormat, 0);
                }

                CloseMe(true, null);
            }
            catch (Exception ex)
            {
                CloseMe(false, ex);
            }
        }
Esempio n. 26
0
 private void InitializeFromStream(Stream stream)
 {
     codec = new RasterCodecs();
     codec.Options.Txt.Load.Enabled = true;
     CodecsImageInfo info = codec.GetInformation(stream, true);
     int lastPage = info.TotalPages;
     ImageData = codec.Load(stream, 0, CodecsLoadByteOrder.BgrOrGray, 1, lastPage);
     codec.Options.Load.XResolution = ImageData.XResolution;
     codec.Options.Load.YResolution = ImageData.YResolution;
     LoadTagsMetaData(stream);
 }
Esempio n. 27
0
        private void InitializeFromStream(Stream stream)
        {
            codec = new RasterCodecs();
            codec.Options.Txt.Load.Enabled = true;
            CodecsImageInfo info     = codec.GetInformation(stream, true);
            int             lastPage = info.TotalPages;

            ImageData = codec.Load(stream, 0, CodecsLoadByteOrder.BgrOrGray, 1, lastPage);
            codec.Options.Load.XResolution = ImageData.XResolution;
            codec.Options.Load.YResolution = ImageData.YResolution;
            LoadTagsMetaData(stream);
        }
Esempio n. 28
0
        private static void ConvertPdfToTif(string fileName)
        {
            Func <int, string> getSaveFileName = pg => Path.GetDirectoryName(fileName)
                                                 + Path.DirectorySeparatorChar
                                                 + Path.GetFileNameWithoutExtension(fileName)
                                                 + "_pg"
                                                 + pg.ToString()
                                                 + ".tif";

            try
            {
                using (var codecs = new RasterCodecs())
                {
                    var info = codecs.GetInformation(fileName, true);
                    for (var pageNumber = 1; pageNumber <= info.TotalPages; pageNumber++)
                    {
                        // Make sure the resulting img has the original resolution
                        var pdfInfo = codecs.GetRasterPdfInfo(fileName, pageNumber);
                        codecs.Options.RasterizeDocument.Load.XResolution = pdfInfo.XResolution;
                        codecs.Options.RasterizeDocument.Load.YResolution = pdfInfo.YResolution;

                        // Save the file using a format appropriate for the bits per pixel
                        var bpp        = pdfInfo.BitsPerPixel;
                        var saveFormat = RasterImageFormat.Tif;

                        if (bpp == 1)
                        {
                            saveFormat = RasterImageFormat.CcittGroup4;
                        }
                        else if (bpp > 1 && bpp < 9)
                        {
                            saveFormat = RasterImageFormat.TifLzw;
                        }
                        else if (bpp == 24)
                        {
                            saveFormat = RasterImageFormat.TifJpeg;
                        }

                        using (var page = codecs.Load(fileName, pageNumber))
                            codecs.Save(page, getSaveFileName(pageNumber), saveFormat, 0);
                    }
                }
                Console.WriteLine("Done");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                Console.ReadLine();
            }
        }
Esempio n. 29
0
        public RasterImage LoadImageFile(string fileName, int firstPage, int lastPage)
        {
            // Load the image
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            RasterImage image = RasterCodecs.Load(fileName, 0, CodecsLoadByteOrder.Bgr, firstPage, lastPage);

            stopWatch.Stop();
            logger.Info($"Image Loaded {fileName} {stopWatch.ElapsedMilliseconds} ");
            return(image);
        }
Esempio n. 30
0
        private void _lstBoxPages_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (_lstBoxPages.Items.Count > 0)
                {
                    double oldScaleFactor = _pictureBox.ScaleFactor;
                    if (oldScaleFactor <= 0)
                    {
                        oldScaleFactor = 1;
                    }

                    if (_pictureBox.Image != null)
                    {
                        _pictureBox.Image.Dispose();
                    }

                    byte[]       buffer = File.ReadAllBytes(_tempFiles[_lstBoxPages.SelectedIndex]);
                    MemoryStream stream = new MemoryStream(buffer);
                    _pictureBox.Image = _codec.Load(stream, 24, CodecsLoadByteOrder.BgrOrGray, 1, 1);

                    if (_miFit.Checked)
                    {
                        View_Clicked(_miFit, new EventArgs());
                    }
                    else
                    {
                        _pictureBox.Zoom(Leadtools.Controls.ControlSizeMode.None, oldScaleFactor, _pictureBox.DefaultZoomOrigin);
                    }
                    stream.Close();
                }

                _pictureBox.Invalidate();
                _lstBoxPages.Invalidate();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "LEADTOOLS Printer Demo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Esempio n. 31
0
    public MyForm3(string title)
    {
        Text = title;
        // Set the size of the form
        Size = new Size(400, 200);

        // Create a new RasterImageList control
        imageList               = new RasterImageList();
        imageList.Dock          = DockStyle.Fill;
        imageList.SelectionMode = RasterImageListSelectionMode.Single;
        imageList.Size          = Size;
        Controls.Add(imageList);
        imageList.BringToFront();

        codecs = new RasterCodecs();

        // Create three items
        string imagesPath = LeadtoolsExamples.Common.ImagesPath.Path;

        for (int i = 0; i < 3; i++)
        {
            // Load the image
            int                 index         = i + 1;
            string              imageFileName = imagesPath + "Image" + index.ToString() + ".cmp";
            RasterImage         image         = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);
            RasterImageListItem item          = new RasterImageListItem(image, 1, "Item" + index.ToString());

            // Select the first item
            if (i == 0)
            {
                item.Selected = true;
            }

            // Add the item to the image list
            imageList.Items.Add(item);
        }

        // Change the item size
        imageList.ItemSize = new Size(200, 200);

        // Change the item image size
        imageList.ItemImageSize = new Size(120, 120);

        // We are going to draw the items ourselves
        imageList.ViewStyle = RasterImageListViewStyle.OwnerDraw;

        // Add a handler to the DrawItem event
        imageList.DrawItem += new EventHandler <RasterImageListDrawItemEventArgs>(rasterImageList_DrawItem);

        // Add the RasterImageList to the control collection.
        Controls.Add(imageList);
    }
Esempio n. 32
0
        /// <summary>
        /// Zoom the image
        /// </summary>
        private void _miZoom_Click(object sender, System.EventArgs e)
        {
            double scaleFactor = _viewer.ScaleFactor;

            if (sender == _miZoomIn)
            {
                if (_originalWidth > _viewer.Image.Width && (scaleFactor == 1))
                {
                    using (RasterCodecs codecs = new RasterCodecs())
                    {
                        CodecsImageInfo _imageInformation = codecs.GetInformation(_fileName, false);
                        switch (_imageInformation.Format)
                        {
                        case RasterImageFormat.J2k:
                            codecs.Options.Jpeg2000.Load.J2kResolution = new LeadSize(_viewer.Image.Width * 2, _viewer.Image.Height * 2);
                            break;

                        case RasterImageFormat.Jp2:
                            codecs.Options.Jpeg2000.Load.Jp2Resolution = new LeadSize(_viewer.Image.Width * 2, _viewer.Image.Height * 2);
                            break;

                        case RasterImageFormat.Cmw:
                            codecs.Options.Jpeg2000.Load.CmwResolution = new LeadSize(_viewer.Image.Width * 2, _viewer.Image.Height * 2);
                            break;
                        }

                        _viewer.Cursor = Cursors.WaitCursor;
                        _viewer.Image.Dispose();
                        _viewer.Image  = codecs.Load(_fileName);
                        this.Text      = String.Format("LEADTOOLS for .NET C# JPEG 2000 Demo {0} X {1}", _viewer.Image.Width, _viewer.Image.Height);
                        _viewer.Cursor = Cursors.Arrow;
                    }
                }
                else
                {
                    scaleFactor *= 2;
                }
            }
            else if (sender == _miZoomOut)
            {
                scaleFactor /= 2;
            }
            else if (sender == _miZoomNormal)
            {
                scaleFactor = 1;
                _viewer.Zoom(ControlSizeMode.None, scaleFactor, _viewer.DefaultZoomOrigin);
            }
            if ((scaleFactor > 0.009) && (scaleFactor < 11))
            {
                _viewer.Zoom(ControlSizeMode.None, scaleFactor, _viewer.DefaultZoomOrigin);
            }
        }
Esempio n. 33
0
        private bool Init()
        {
            // Check support required to use this program
            if (RasterSupport.IsLocked(RasterSupportType.Barcodes1D) && RasterSupport.IsLocked(RasterSupportType.Barcodes2D))
            {
                Messager.ShowError(this, BarcodeGlobalization.GetResxString(GetType(), "Resx_LEADBarcodeSupport"));
                return(false);
            }

            try
            {
                _rasterCodecs = new RasterCodecs();
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, string.Format("RasterCodec initialize error: {0}", ex.Message));
                return(false);
            }

            // this is very important, must be placed leadtools.engine.dll in this path
            _rasterCodecs.Options.Pdf.InitialPath = AppDomain.CurrentDomain.BaseDirectory;

            _barcodeOptions = BarcodeOptions.Load();

            //BarcodeSymbology[] supportedSymbologies = BarcodeEngine.GetSupportedSymbologies();
            WriteLine(string.Format("{0} Supported symbologies:", _barcodeOptions.ReadOptionsSymbologies.Length), TraceEventType.Information);
            foreach (BarcodeSymbology symbology in _barcodeOptions.ReadOptionsSymbologies)
            {
                WriteLine(string.Format("{0}: {1}", symbology, BarcodeEngine.GetSymbologyFriendlyName(symbology)), TraceEventType.Information);
            }
            WriteLine(string.Format("----------"), TraceEventType.Information);

            _sampleSymbologiesRasterImage = null;

            // Create the barcodes symbologies multi-frame RasterImage
            using (Stream stream = GetType().Assembly.GetManifestResourceStream("BarcodeSplitManage.Resources.Symbologies.tif"))
            {
                _rasterCodecs.Options.Load.AllPages = true;
                _sampleSymbologiesRasterImage       = _rasterCodecs.Load(stream);
            }

            _barcodeEngine = new BarcodeEngine();
            _barcodeEngine.Reader.ImageType = BarcodeImageType.Unknown;
            _barcodeEngine.Reader.EnableReturnFourPoints = false;
            // Continue on errors
            _barcodeEngine.Reader.ErrorMode = BarcodeReaderErrorMode.IgnoreAll;

            _directorySettings = new DirectorySettings();

            return(true);
        }
Esempio n. 34
0
        private void WriteBarcodeForm_Load(object sender, System.EventArgs e)
        {
            // initialize the _viewer object
            _viewer           = new ImageViewer();
            _viewer.Dock      = DockStyle.Fill;
            _viewer.BackColor = Color.DarkGray;
            Controls.Add(_viewer);
            _viewer.BringToFront();

            // initialize the codecs object.
            _codecs = new RasterCodecs();

            try
            {
                string imagePath = Path.Combine(DemosGlobal.ImagesFolder, "license_sample_rear_blank.png");
                _viewer.Image = _codecs.Load(imagePath);
            }
            catch
            {
                _viewer.Image = RasterImage.Create(1100, 700, 24, 150, RasterColor.White);
            }

            _barcodeEngine = new BarcodeEngine();
            _writeOptions  = (PDF417BarcodeWriteOptions)_barcodeEngine.Writer.GetDefaultOptions(BarcodeSymbology.PDF417);

            //Refer to AAMVA CDS 2016 Section D.3 thru D.11.2

            //Must range from 0.0066 to 0.015 inches
            _writeOptions.XModule = 15; //0.015
            //Must >= 3
            _writeOptions.XModuleAspectRatio = 3;
            //Error level must be at least 3, 5 is recommended
            _writeOptions.ECCLevel = PDF417BarcodeECCLevel.Level5;
            //Default WidthAspectRatio is 2:1. 4:1 looks similar to ID barcodes in the wild
            _writeOptions.SymbolWidthAspectRatio = 4;
            //Default quiet zone for PDF417 is 2 * XModule


            _viewer.BeginUpdate();
            WriteBarcodeInteractiveMode writeBarcodeInteractiveMode = new WriteBarcodeInteractiveMode(_barcodeEngine, _aamvaData, _writeOptions);

            writeBarcodeInteractiveMode.IsEnabled = true;
            ImageViewerPanZoomInteractiveMode panZoomInteractiveMode = new ImageViewerPanZoomInteractiveMode();

            _viewer.InteractiveModes.Add(writeBarcodeInteractiveMode);
            _viewer.InteractiveModes.Add(panZoomInteractiveMode);
            _viewer.EndUpdate();


            UpdateMyControls();
        }
Esempio n. 35
0
        public static bool ConvertDrawingImage(string strBasePath, string strSavePath)
        {
            try
            {
                RasterCodecs codecs = new RasterCodecs();
                RasterImage image = codecs.Load(strBasePath, 0, Leadtools.Codecs.CodecsLoadByteOrder.BgrOrGray, 1, 1);

                return SaveDrawingImage(image, strSavePath);
            }
            catch(Exception ex)
            {
                throw new Exception("WCF : Failed ConvertDrawingImage('" + ex.Message + "')");
            }
        }
        public static void GrayscaleTransformerVersion11(string srcFileName, string DestFileName)
        {
            RasterCodecs codecs = new RasterCodecs();
            UnlockLeadToolsDocumentSupport();

            IRasterImage image = null;
            int pageCount = 0;
            image = codecs.Load(srcFileName);

            pageCount = image.PageCount;
            var bitsPerPixel = 12;

            codecs.Save(image, DestFileName, RasterImageFormat.Tif, bitsPerPixel, 1, pageCount, 1, CodecsSavePageMode.Append);
            image.Dispose();
        }
Esempio n. 37
0
        private void ConvertFileFormat()
        {
            
            RasterCodecs codec = new RasterCodecs();
            //codec.Options.s
           // CodecsLoadOptions options = new CodecsLoadOptions();


            CodecsPdfLoadOptions options = codec.Options.Pdf.Load;


            //CodecsRtfLoadOptions options1 = codec.Options.Rtf.Load;
            //options1.

            RasterImage image = codec.Load(@"c:\leadtools\gas.pdf", 0, CodecsLoadByteOrder.RgbOrGray, 1, 1);
            

            codec.Save(image, @"c:\leadtools\gas.tif", RasterImageFormat.TifxFaxG4, 1, 1, image.PageCount, 1, CodecsSavePageMode.Overwrite);
            MessageBox.Show("Done");
        }
        //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();
        }
Esempio n. 39
0
        public static void MergeFiles(string mainFile, string appendFile, bool annotation)
        {


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

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

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


        }
Esempio n. 40
0
        private void LoadStream(RasterCodecs codec)
        {
            if (stream == null )
            {
                _image = null;
                return;
            }

            CodecsTiffLoadOptions options = codec.Options.Tiff.Load;

            /*
            codec.Options.Load.Compressed = true;
             */

            //    codec.Options.Load.XResolution = 204;
            //    codec.Options.Load.YResolution = 196;
            //    


            CodecsImageInfo info = codec.GetInformation(stream, true);
            int firstPage = 1;
            int lastPage = info.TotalPages;
            _image = codec.Load(stream, 0, CodecsLoadByteOrder.BgrOrGray, firstPage, lastPage);

        }
Esempio n. 41
0
        void DROC_RibbonKeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Alt && e.Shift && e.KeyCode == Keys.K)
                {
                    Autosave4Toshiba();
                }
                if (e.Alt && e.Shift && e.Control && e.KeyCode == Keys.A)
                {
                    AutoGenLstFile = true;
                }
                if (e.Control && e.Alt && e.Shift && e.KeyCode == Keys.N) notConnecttoFPD = true;
                if (isAcq)
                {
                    if (e.KeyCode == Keys.N || e.KeyCode == Keys.E)
                    {
                        try
                        {
                            frm_QuickRegistration newForm = new frm_QuickRegistration(m_intCurrDevice1);
                            newForm.ImgPath = txtImgDir.Text.Trim();
                            newForm.WLDataSource = m_dtWLDataSource;
                            newForm.grdList = grdWorkList;
                            newForm.Act = action.Insert;
                            newForm.ShowDialog();
                            SetSuspendingInfo();
                            if (newForm.IsBeginExam)
                            {
                                ModifyWorkListButtons();
                                BeginExam();
                                ShortCut2AddProc(Last_Anatomy, Last_Projection,true,ref _newDetailID);
                            }
                        }
                        catch
                        {
                        }
                        return;
                    }
                    if (e.KeyCode == Keys.S)
                    {
                        cmdSaveImg_Click(cmdSaveImg, new EventArgs());
                        return;
                    }
                    if (e.KeyCode == Keys.P)
                    {
                        cmdDicomPrinter_Click(cmdDicomPrinter, new EventArgs());
                        return;
                    }
                    if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
                    {
                        cmdFlipV_Click(cmdFlipV, new EventArgs());
                        return;
                    }
                    if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up)
                    {
                        cmdFlipH_Click(cmdFlipH, new EventArgs());
                        return;
                    }
                    if (e.KeyCode == Keys.C )
                    {
                        _DicomMedicalViewer.AutoAddRec4CropWhenPressC();
                        return;
                    }

                    if (e.KeyCode == Keys.R)
                    {
                        ChangeSymBol(_DicomMedicalViewer._medicalViewer, _DicomMedicalViewer._medicalViewerCellIndex, _R);
                        return;
                    }
                    if (e.KeyCode == Keys.L)
                    {
                        ChangeSymBol(_DicomMedicalViewer._medicalViewer, _DicomMedicalViewer._medicalViewerCellIndex, _L);
                        return;
                    }
                    if (e.KeyCode == Keys.U )
                    {
                        ChangeSymBol(_DicomMedicalViewer._medicalViewer, _DicomMedicalViewer._medicalViewerCellIndex, _U);
                        return;
                    }
                    if (e.KeyCode == Keys.B )
                    {
                        ChangeSymBol(_DicomMedicalViewer._medicalViewer, _DicomMedicalViewer._medicalViewerCellIndex, _B);
                        return;
                    }
                    if (e.KeyCode == Keys.O )
                    {
                        AddOtherSymbol();
                        return;
                    }
                }
                if (e.KeyCode == Keys.Enter) ProcessTabKey(true);

                if (_DicomMedicalViewer.IsValidCell())
                {
                    if (e.KeyCode == Keys.Back || e.KeyCode == Keys.F5)
                    {
                        try
                        {
                            using (RasterCodecs _codecs = new RasterCodecs())
                            {
                                //_codecs.Options.Load.DiskMemory = true;
                                RasterImage temp = _codecs.Load(CurrCellFileName);
                                Convert2MedicalViewerCell(_DicomMedicalViewer._medicalViewer.Cells[_DicomMedicalViewer._medicalViewerCellIndex]).Image = temp.CloneAll();
                                _DicomMedicalViewer.try2FreeImage(ref temp);
                            }
                        }
                        catch
                        {
                        }
                    }
                    if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Right)
                    {
                        Rotate(_DicomMedicalViewer._medicalViewer, 90,false);


                    }
                    if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Left)
                    {
                        Rotate(_DicomMedicalViewer._medicalViewer, -90,false);
                    }
                }
                if (e.Modifiers == Keys.Control && (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down))
                {
                    //a.PerformClick();
                }
                if (e.Modifiers == Keys.Alt && (e.KeyCode == Keys.Right || e.KeyCode == Keys.Left))
                {
                    //av.PerformClick();
                }
                if (e.KeyCode == Keys.F12)
                {
                    lstFPD560_DoubleClick(lstFPD560,new EventArgs());
                    //_FullScreen.ShowFullScreen();
                    return;
                }
                if (e.Modifiers == Keys.Control && e.KeyCode == Keys.R)
                {
                    mdlStatic.isDisplayImg=false;
                    isLoadding = false;
                    ViewImg();
                    return;
                }
                if (e.KeyCode == Keys.F2 && !Running)
                {
                    cmdRepeatAcquisition.PerformClick();
                }
                if (e.KeyCode == Keys.N && e.Control && e.Alt)
                {
                    UpdateDiagnostic();
                }
                if (e.KeyCode == Keys.F6)
                {
                    //SetPermission();
                }
                if (e.KeyCode == Keys.Escape && Running)
                {
                    cmdSendtoServer.PerformClick();
                }
                if (e.Modifiers == Keys.Control && (e.KeyCode == Keys.V))
                {
                    //bool FileErr = false;
                    //string Err = "";
                    //System.Collections.Specialized.StringCollection _StrClt = Clipboard.GetFileDropList();
                    //foreach (string s in _StrClt)
                    //{
                    //    try
                    //    {
                    //        OpenDicom(_DicomMedicalViewer._medicalViewer, s);
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        Err += @"File:" + s + " không hợp lệ!\n";
                    //        FileErr = true;
                    //    }
                    //}
                    //if (FileErr) MessageBox.Show(Err);
                }
            }
            catch
            {
                return;
            }
        }
Esempio n. 42
0
        public void TestOpen()
        {
            string fileName = @"C:\Images\Chest.dcm";
            if (File.Exists(fileName))
            {
                try
                {

                    using (RasterCodecs _codecs = new RasterCodecs())
                    {
                        using (RasterImage _image = _codecs.Load(fileName))
                        {
                            MedicalViewerMultiCell cell = new MedicalViewerMultiCell();
                            cell.FitImageToCell = true;
                            cell.Columns = 1;
                            cell.Rows = 1;
                            DicomDataSet ds = new DicomDataSet();
                            try
                            {

                                ds.Load(fileName, DicomDataSetLoadFlags.LoadAndClose);
                            }
                            catch (Exception ex) { ds = null; }
                            if (ds != null)
                            {
                                // dosomething here
                            }
                            _DicomMedicalViewer._medicalViewer.Cells.Add(cell);
                            cell.Image = _image.CloneAll();
                            cell.Selected = true;
                            _DicomMedicalViewer._medicalViewer.Invalidate();
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Esempio n. 43
0
        private void LoadImageList()
        {
            if (fileName == null || "".Equals(fileName))
            {
                return;
            }
            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException("An error occurred while loading the image list." + Environment.NewLine +
                    "Error CNF-543 in " + FORM_NAME + ".LoadImageList()");
            }

            RasterCodecs codec = new RasterCodecs();

            CodecsImageInfo info = codec.GetInformation(fileName, true);

            RasterPaintProperties paintProp = imageList.PaintProperties;
            paintProp.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray;

            int lastPage = info.TotalPages;
            image = codec.Load(fileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, lastPage);
            imageList.Items.Clear();
            int totalCount = image.PageCount;
            for (int i = 1; i <= totalCount; ++i)
            {
                RasterImageListItem imageItem = new RasterImageListItem(image, i, "Page " + i.ToString());
                imageList.Items.Add(imageItem);

            }

            LoadCheckBox(totalCount);
        }
Esempio n. 44
0
        private static void DoExtraction(string srcFileName, string destFileName, int[] pageNumList, bool annotation)
        {
            RasterCodecs codec = new RasterCodecs();
            RasterImage image = null;
            RasterTagMetadata[] tagsData = null;

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

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

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

        }
Esempio n. 45
0
 void SaveThumbnail(MedicalViewerCell _cell)
 {
     try
     {
         string _dcmFile = "";
         if (_cell.Tag != null) _dcmFile = _cell.Tag.ToString();
         int Detail_ID = _cell.TabIndex;
         if (_dcmFile.Trim() != "")
         {
             using (RasterCodecs _Codecs = new RasterCodecs())
             {
                 using (RasterImage _temp = _Codecs.Load(_dcmFile))
                 {
                     _Codecs.Save(_temp.CreateThumbnail(83, 100, _temp.BitsPerPixel, _temp.ViewPerspective, RasterSizeFlags.Bicubic), thumbnailFileName, RasterImageFormat.Png, 8);
                     UpdateThumbnailImgOnScheduled(thumbnailFileName,Detail_ID, 1);
                 }
             }
         }
     }
     catch
     {
     }
 }
Esempio n. 46
0
         public void OpenDicom( ref bool IsCroping, ref int _Idx, string fileName, bool IsOnlyImg, bool CanCreatePicBox)
         {
             //Stopwatch _sw = new Stopwatch();
             try
             {
                 _DicomMedicalViewer._medicalViewer.BeginUpdate();
                 pnlScheduled.Enabled = false;
                 //_sw.Start();
                
                 #region Chế độ Demo
                 if (_AppMode == AppType.AppEnum.AppMode.Demo && !File.Exists(fileName))
                 {
                     ScheduledControl _selected = GetSelectedScheduled();
                     bool _isSelected = true;
                     string RAWFilePath = "";
                     //Tạo các thư mục theo cấp ngày\Bệnh nhân(Mã bệnh nhân _ Tên Bệnh nhân _ Tuổi)
                     if (!Directory.Exists(txtImgDir.Text + @"\" + SubDirLv1())) Directory.CreateDirectory(txtImgDir.Text + @"\" + SubDirLv1());
                     if (!Directory.Exists(txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient())) Directory.CreateDirectory(txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient());
                     //Kiểm tra nếu chưa chọn thủ tục nào thì cần lưu ảnh thành tên file theo định dạng
                     //YYYY_MM_DD_HH_mm_ss
                     if (_selected == null || RAWFileNameWillbeCreated == "NONE_SELECTED")
                     {
                         _isSelected = false;
                         RAWFileNameWillbeCreated = "NONE_SELECTED_" + Utility.GetYYYYMMDDHHMMSS(DateTime.Now);
                         if (!Directory.Exists(txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient() + @"\NONE_SELECTED")) Directory.CreateDirectory(txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient() + @"\NONE_SELECTED");
                         RAWFilePath = txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient() + @"\NONE_SELECTED\" + RAWFileNameWillbeCreated + ".RAW";
                     }
                     else
                         RAWFilePath = txtImgDir.Text + @"\" + SubDirLv1() + @"\" + SubDirLv2_Patient() + @"\" + RAWFileNameWillbeCreated + ".RAW";//RAWFileNameWillbeCreated=REGNUM+_Detail_ID+_ACode+_Pcode tại phần click của Scheduled
                     fileName = Application.StartupPath + @"\DemoImg\" + m_strCurrACode + "-" + m_strCurrPCode + ".DCM";
                     string destFile = RAWFilePath.ToUpper().Replace(".RAW", ".DCM");
                     try2MoveFileInDemoMode(fileName, destFile);
                     fileName = destFile;
                     //Tự động cập nhật kết quả đã có hình ảnh
                     AutoUpdateResultAfterCapturingPictureFromModality();
                     AutoUpdatePatientInforInDcmFile_DemoMode(Path.GetDirectoryName(fileName), fileName, txtID2.Text, txtName2.Text, txtAge.Text, Sex,_selected.StudyInstanceUID, _selected.SeriesInstanceUID, _selected.SOPInstanceUID);
                 }
                 #endregion

                 isLoadding = true;
                 //stopToolStripMenuItem1_Click(mnuStop, new EventArgs());
                 TempCrop = IsCroping;
                 int _ww = 0;
                 int _wc = 0;
                 this.Text = MultiLanguage.GetText(globalVariables.DisplayLanguage, "VietBaIT JCS - DROC", "VietBaIT JSC-DROC");
                 if (!IsCroping) FilePath = fileName;
                 bool IsRawFile = false;
                 _images = 1;
                
                     try
                     {
                         #region Xử lý lại ảnh dcm từ ảnh gốc(Raw file)
                         try
                         {
                             if (IsGenDcmFromRaw)
                             {
                                 IsGenDcmFromRaw = false;
                                 string tempf_raw = fileName.ToUpper().Replace(".DCM", ".RAW");

                                 //Kiểm tra xem có ảnh Raw không
                                 if (File.Exists(tempf_raw))
                                 {
                                     //xóa file Dcm đang có
                                     string tempf_dcm = fileName.ToUpper().Replace(".RAW", ".DCM");
                                     try
                                     {
                                         File.Delete(tempf_dcm);
                                     }
                                     catch
                                     {
                                     }
                                     //Gán lại giá trị cho fileName để bước kế tiếp load lại raw file
                                     fileName = tempf_raw;
                                 }

                             }
                         }
                         catch(Exception ex0)
                         {
                             AppLogger.LogAction.LogActions("==>OpenDicom.if (IsGenDcmFromRaw)().Exception occurred at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "." + ex0.ToString());
                         }
                         try
                         {
                             if (Path.GetExtension(fileName).ToUpper().Contains("RAW"))
                             {
                                 if (IsUsingDicomConverter || lblAutoDcmConverter.IsChecked)//Tự động convert thành file Dicom
                                 {
                                     ConvertRaw2DicomFileReprocess(fileName);
                                     AutoUpdateResultAfterCapturingPictureFromModality();
                                     fileName = fileName.ToLower().Replace(".raw", ".dcm");
                                     IsUsingDicomConverter = true;
                                     v_blnHasConvertRawin2DicomFile = true;
                                     //Thực hiện thuật toán xử lý ảnh ở ngay sau bước load ảnh Dicom

                                 }
                                 else
                                 {
                                     new frm_LargeMsgBoxOK(MultiLanguage.GetText(globalVariables.DisplayLanguage, "Thông báo", "Warning"), MultiLanguage.GetText(globalVariables.DisplayLanguage, "Cần vào tab Cấu hình đánh dấu vào mục tự động Convert thành file Dicom", "go to Configuration Tab and check Auto Convert to Dicom File"), MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đã hiểu", "OK"), MultiLanguage.GetText(globalVariables.DisplayLanguage, "Không hiểu", "Cancel")).ShowDialog();
                                 }
                             }
                         }
                         catch (Exception ex01)
                         {
                             AppLogger.LogAction.LogActions("==>OpenDicom.ReGenDcmFromRAWFile().Exception occurred at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "." + ex01.ToString());
                         }
                         #endregion
                         
                         if (File.Exists(fileName))
                         {
                             AppLogger.LogAction.AddLog2List(lstFPD560,DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + fileName + " exists");
                             FreeMemoryCapturedByMedicalviewerCell();
                             using (RasterCodecs _codecs = new RasterCodecs())
                             {
                                 //using (CounterDialog counter = new CounterDialog(this, _codecs))
                                 //{
                                 //    counter.Show(this);
                                 //    counter.Update();
                                 //if (chkLoadIn2Memory.IsChecked==false ) _codecs.Options.Load.DiskMemory = true;

                                 if (_codecs.Options.Load.DiskMemory) SetText(lblUsingMemo, "MEM");
                                 else SetText(lblUsingMemo, "NOTMEM");
                                 using (RasterImage _image = _codecs.Load(fileName))
                                 {

                                     cmdCreateDcmfromRaw.Enabled = true;
                                     //try2FreeImage(orginalImg);
                                    _DicomMedicalViewer.try2FreeImage(ref orginalImg);
                                     // try2FreeOriginalImage();
                                     if (_CurrCell != null)
                                     {
                                         RasterImage img = _CurrCell.Image;
                                         _DicomMedicalViewer.try2FreeImage(ref img);
                                     }
                                     orginalImg = _image.CloneAll();
                                     //Xóa các cell sau khi đã giải phóng bộ nhớ
                                     _DicomMedicalViewer._medicalViewer.Cells.Clear();
                                     //Tạo cell mới
                                     MedicalViewerMultiCell cell = new MedicalViewerMultiCell();
                                     cell.BeginUpdate();
                                     cell.FitImageToCell = true;
                                     cell.Columns = 1;
                                     cell.Rows = 1;
                                     _DicomMedicalViewer.InitializeCell(cell);
                                     _DicomMedicalViewer.CopyPropertiesFromGlobalCell(cell);
                                     _Idx = 0;
                                     if (IsOnlyImg) return;
                                     CurrCellFileName = fileName;
                                     //cell.SetTag(4, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Frame);
                                     cell.SetTag(6, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Scale);
                                     cell.SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData);
                                     //cell.SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.FieldOfView);
                                     cell.SetTag(0, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.RulerUnit);
                                     DicomDataSet ds = new DicomDataSet();

                                     try
                                     {
                                         ds.Load(fileName, DicomDataSetLoadFlags.LoadAndClose);
                                         CurrentDicomDS = ds;
                                     }
                                     catch (Exception ex) { ds = null; }
                                     //DicomDS.Add(fileName, ds);
                                     if (ds != null)
                                     {

                                         if (IsRawFile)
                                             AutpSetDefaultTagForImgInfor(fileName, ds);
                                         _ww = Convert.ToInt32(GetStringValue(ds, DicomTag.WindowWidth));
                                         _wc = Convert.ToInt32(GetStringValue(ds, DicomTag.WindowCenter));
                                         string ID_Name = GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientID) + " " + GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientName);
                                         string Birthday_Sex_Age = "";
                                         string BD = GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientBirthDate).Trim();
                                         string BT = GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientBirthTime).Trim();
                                         string Sex = TranslateSex(GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientSex).Trim());
                                         string Age = GetStringValue(ds, Leadtools.Dicom.DicomTag.PatientAge).Trim();
                                         ID_Name_Age_Sex = ID_Name + " " + Age + " " + Sex;
                                         if (BD != "") Birthday_Sex_Age += BD;
                                         //if (BT != "") Birthday_Sex_Age += BD;
                                         if (Sex != "") Birthday_Sex_Age += " [" + Sex + "] ";
                                         if (Age != "") Birthday_Sex_Age += Age + " T";
                                         //Mã+Tên BN
                                         cell.SetTag(0, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, ID_Name);
                                         //Ngày sinh-Giới tính-Tuổi
                                         cell.SetTag(1, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, Birthday_Sex_Age);
                                         //Các thông tin khác

                                         cell.SetTag(0, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, HospitalName);
                                         cell.SetTag(1, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, DepartmentName);
                                         cell.SetTag(2, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
                                     }
                                     else
                                     {
                                         //Mã+Tên BN
                                         cell.SetTag(0, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "");
                                         //Ngày sinh-Giới tính-Tuổi
                                         cell.SetTag(1, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "");
                                         //Các thông tin khác

                                         cell.SetTag(0, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "");
                                         cell.SetTag(1, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "");
                                         cell.SetTag(2, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "");
                                     }

                                     //Load Annotation
                                     string Anfn = GetAnnPath(fileName);
                                     if (System.IO.File.Exists(Anfn))
                                     {
                                         LoadAnnotation(cell, Anfn, true);
                                     }

                                    _DicomMedicalViewer.ApplyToCell(cell);
                                     cell.ShowTags = lblDisplayTag.IsChecked;
                                     cell.DisplayRulers = (MedicalViewerRulers)cboRuler.SelectedIndex;
                                     AddNewMecicalViewerCell(cell);
                                     int CellCount = _DicomMedicalViewer._medicalViewer.Cells.Count;
                                     _Idx = CellCount - 1;
                                     //Dùng CloneAll() để giải phóng _image

                                     cell.Tag = fileName;
                                     if (GetSelectedScheduled() != null)
                                         cell.TabIndex = GetSelectedScheduled().DETAIL_ID;
                                     else
                                         cell.TabIndex = m_intCurrentDetail_ID <= 0 ? 0 : m_intCurrentDetail_ID;
                                     //v_blnHasConvertRawin2DicomFile=true xảy ra ở 2 sự kiện
                                     //1. Nhận ảnh từ FPD và có tự động chuyển thành file Dicom
                                     //2. Nhận ảnh từ FPD và để dưới dạng file RAW, sau đó tại hàm OpenDicom() nếu chưa có ảnh Dcm sẽ tự động Convert file RAW thành DCM
                                     if (v_blnHasConvertRawin2DicomFile && lblDisplayRaw.ImageIndex != 0)
                                     {
                                             using (Cursor _Cursor = Cursors.WaitCursor)
                                             {
                                                 AppLogger.LogAction.ShowEventStatus(lblFPDStatus,MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đang xử lý ảnh...", "image processing..."));
                                                 AppLogger.LogAction.AddLog2List(lstFPD560,DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đang xử lý ảnh...", "image processing..."));
                                                 _DicomMedicalViewer.ApplyIEConfig(_currDRIEData, _image, lblGridMode.IsChecked, lblAppliedMed.IsChecked);
                                                 AutoApplyWW_WC(_image);
                                                 AppLogger.LogAction.AddLog2List(lstFPD560,DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đã xử lý xong...", "image processed..."));
                                                 AppLogger.LogAction.ShowEventStatus(lblFPDStatus,MultiLanguage.GetText(globalVariables.DisplayLanguage, "Đã xử lý xong...", "image processed..."));

                                                 if ( ((_FPDMode != AppType.AppEnum.FPDMode.Other && chkAutoVFlip1.IsChecked) || (_FPDMode == AppType.AppEnum.FPDMode.Other && ((FPDSeq == 1 && chkAutoVFlip1.IsChecked) || (FPDSeq == 2 && chkAutoVFlip2.IsChecked)))))
                                                 {
                                                     _DicomMedicalViewer.ApplyFilter(_image, new FlipCommand(true));
                                                 }
                                                 if (((_FPDMode != AppType.AppEnum.FPDMode.Other && chkAutoHFlip1.IsChecked) || (_FPDMode == AppType.AppEnum.FPDMode.Other && ((FPDSeq == 1 && chkAutoHFlip1.IsChecked) || (FPDSeq == 2 && chkAutoHFlip2.IsChecked)))))
                                                 {
                                                     _DicomMedicalViewer.ApplyFilter(_image, new FlipCommand(false));
                                                 }
                                                 if (AUTO_FLIPV == 1)
                                                 {
                                                     _DicomMedicalViewer.ApplyFilter(_image, new FlipCommand(true));
                                                 }
                                                 if (AUTO_FLIPH == 1)
                                                 {
                                                     _DicomMedicalViewer.ApplyFilter(_image, new FlipCommand(false));
                                                 }
                                                 AutoDetectRowsAndCols(cell, _image.PageCount);
                                                 cell.Image = _image.CloneAll();
                                                 if (!_DicomMedicalViewer.IsValidCell()) return;
                                                 _DicomMedicalViewer._medicalViewer.Cells.SelectAll(false);
                                                 _DicomMedicalViewer._medicalViewer.VisibleRow = _Idx;
                                                 cell.Selected = true;
                                                 _DicomMedicalViewer._medicalViewer.Invalidate();
                                                 if (AllowAppliedWL)
                                                 {
                                                     _DicomMedicalViewer.SetWindowLevel(cell, WW,WC);
                                                     
                                                 }
                                                 AllowAppliedWL = true;
                                             }

                                             _ww = WW;
                                             _wc = WC;
                                         //Thử tạo thông tin Annotation
                                         //CreateDefaultAnnotationOnImage(_DicomMedicalViewer._medicalViewer, Color.White, Color.Black, HospitalName, DepartmentName, ID_Name_Age_Sex, DateTime.Now.ToString("dd/MM/yyyy"));
                                         SaveImg();
                                         v_blnHasConvertRawin2DicomFile = false;
                                         //Tự động chuyển sang Tab xử lý ảnh
                                         tabCtrlAcq.SelectedTab = tabPageImgTools;
                                         //PlayBeep(5);
                                     }
                                     else
                                     {
                                         AutoDetectRowsAndCols(cell, _image.PageCount);
                                         cell.Image = _image.CloneAll();
                                         //cell.Bounds = cell.GetDisplayedClippedImageRectangle();
                                         if (!_DicomMedicalViewer.IsValidCell()) return;
                                         _DicomMedicalViewer._medicalViewer.Cells.SelectAll(false);
                                         _DicomMedicalViewer._medicalViewer.VisibleRow = _Idx;
                                         cell.Selected = true;
                                         _DicomMedicalViewer._medicalViewer.Invalidate();
                                         if (_AppMode == AppType.AppEnum.AppMode.Demo && FirstExposure)
                                         {
                                             SaveImg();
                                         }
                                     }
                                     //Áp dụng windowLeveling khi thực hiện lưu ảnh.
                                     //AutoApplyWW_WC();
                                     if (_ww != 0)
                                     {
                                         _DicomMedicalViewer.SetWindowLevel(cell,_ww,_wc);

                                         _DicomMedicalViewer._medicalViewer.Invalidate();
                                     }
                                     cell.EndUpdate();
                                     _DicomMedicalViewer._medicalViewer.Invalidate();
                                 }
                                 // }
                             }
                             _DicomMedicalViewer._medicalViewer.EndUpdate();
                             AppLogger.LogAction.ShowEventStatus(lblFPDStatus,MultiLanguage.GetText(globalVariables.DisplayLanguage, "Mời bạn tiếp tục xử lý", "Image Result"));
                         }
                         else
                         {
                             mdlStatic.isDisplayImg = false;
                             if (_AppMode == AppType.AppEnum.AppMode.License || (_AppMode == AppType.AppEnum.AppMode.Demo && _ViewState == AppType.AppEnum.ViewState.Capture))
                                 MessageBox.Show("Không tồn tại file ảnh sau:\n" + fileName);
                         }
                     }
                     catch (Exception ex)
                     {

                         AppLogger.LogAction.LogActions("==>OpenDicom.SecondsException().Exception occurred at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "." + ex.ToString());
                         Utility.ShowMsg("2225 " + ex.ToString() + "\n" + fileName);
                         GC.Collect();
                         isLoadding = false;
                        
                         DeleteCurrentImg(_DicomMedicalViewer._medicalViewer, _DicomMedicalViewer._medicalViewerCellIndex);

                     }
                     finally
                     {
                         isLoadding = false;

                     }
                
                 isLoadding = false;
             }
             catch (Exception ex1)
             {
                 AppLogger.LogAction.LogActions("==>OpenDicom.FirstException().Exception occurred at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "." + ex1.ToString());
                 AppLogger.LogAction.AddLog2List(lstFPD560,"0002: " + ex1.Message);
             }
             finally
             {
                 _DicomMedicalViewer._medicalViewer.BeginUpdate();
                 pnlScheduled.Enabled = true;
                //_sw.Stop();
                 //AppLogger.LogAction.ShowEventStatus(lblFPDStatus,((decimal)_sw.ElapsedMilliseconds / 1000).ToString());
                 IsUsingDicomConverter = false;
                 lblMemory.Text = getAvailableRAM();
                 //Kiểm tra nếu đang chế độ Crop mà lại chọn mục xem lại ảnh gốc thì cần khôi phục lại chế độ đó
                 if (_DicomMedicalViewer._IsCropping && IsLoadOriginalImage)
                 {
                     cmdAcqCrop_Click(cmdAcqCrop,new EventArgs());//Trạng thái ban đầu
                     cmdAcqCrop_Click(cmdAcqCrop, new EventArgs());//Trạng thái Crop
                 } 
             }
         }