Exemplo n.º 1
0
        void ConvertJpeg2000(DicomDataSet ds)
        {
            DicomJpeg2000Options options = ds.DefaultJpeg2000Options;

            Console.WriteLine("JPEG 2000 Options:");
            Console.WriteLine("DicomJpeg2000Options.UseColorTransform            is : {0}", options.UseColorTransform);
            Console.WriteLine("DicomJpeg2000Options.DerivedQuantization          is : {0}", options.DerivedQuantization);
            Console.WriteLine("DicomJpeg2000Options.TargetFileSize               is : {0}", options.TargetFileSize);
            Console.WriteLine("DicomJpeg2000Options.ImageAreaHorizontalOffset    is : {0}", options.ImageAreaHorizontalOffset);
            Console.WriteLine("DicomJpeg2000Options.ImageAreaVerticalOffset      is : {0}", options.ImageAreaVerticalOffset);
            Console.WriteLine("DicomJpeg2000Options.ReferenceTileWidth           is : {0}", options.ReferenceTileWidth);
            Console.WriteLine("DicomJpeg2000Options.ReferenceTileHeight          is : {0}", options.ReferenceTileHeight);
            Console.WriteLine("DicomJpeg2000Options.TileHorizontalOffset         is : {0}", options.TileHorizontalOffset);
            Console.WriteLine("DicomJpeg2000Options.TileVerticalOffset           is : {0}", options.TileVerticalOffset);
            Console.WriteLine("DicomJpeg2000Options.DecompositionLevels          is : {0}", options.DecompositionLevels);
            Console.WriteLine("DicomJpeg2000Options.ProgressingOrder             is : {0}", options.ProgressingOrder);
            Console.WriteLine("DicomJpeg2000Options.CodeBlockWidth               is : {0}", options.CodeBlockWidth);
            Console.WriteLine("DicomJpeg2000Options.CodeBlockHeight              is : {0}", options.CodeBlockHeight);
            Console.WriteLine("DicomJpeg2000Options.UseSopMarker                 is : {0}", options.UseSopMarker);
            Console.WriteLine("DicomJpeg2000Options.UseEphMarker                 is : {0}", options.UseEphMarker);
            Console.WriteLine("DicomJpeg2000Options.RegionOfInterest             is : {0}", options.RegionOfInterest);
            Console.WriteLine("DicomJpeg2000Options.UseRegionOfInterest          is : {0}", options.UseRegionOfInterest);
            Console.WriteLine("DicomJpeg2000Options.RegionOfInterestWeight       is : {0}", options.RegionOfInterestWeight);
            Console.WriteLine("DicomJpeg2000Options.RegionOfInterestRectangle    is : {0}", options.RegionOfInterestRectangle);

            options.CompressionControl = DicomJpeg2000CompressionControl.Ratio;
            options.CompressionRatio   = 50;

            Console.WriteLine("Changed CompressionControl to DicomJpeg2000CompressionControl.Ratio and DicomJpeg2000CompressionControl.CompressionRatio to 50");
            //https://www.leadtools.com/help/leadtools/v19/dh/di/dicomdataset-setimage.html
            ds.Jpeg2000Options = options;
            ds.ChangeTransferSyntax(DicomUidType.JPEG2000, 2, ChangeTransferSyntaxFlags.None);
        }
        public virtual void BeforeAddingToDicomDir
        (
            string referencedInstancePath,
            CompositeInstanceDataSet.InstanceRow instance,
            bool allowLossyCompression
        )
        {
            if (instance.TransferSyntax != DicomUidType.ExplicitVRLittleEndian)
            {
                using (DicomDataSet ds = new DicomDataSet( ))
                {
                    ds.Load(referencedInstancePath, DicomDataSetLoadFlags.None);

                    ds.ChangeTransferSyntax(DicomUidType.ExplicitVRLittleEndian, 0, ChangeTransferSyntaxFlags.None);

                    ds.Save(referencedInstancePath, DicomDataSetSaveFlags.None);
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            _storageScu = new StorageScu(editAE.Text, editAE.Text, editIP.Text, Convert.ToInt16(editPort.Text));
            _storageScu.ImageStoreCompleted += new EventHandler <StorageInstance>(storageScu_StoreCompleted);

            //_storageScu.AddStorageInstance(new StorageInstance("AnotherFile.dcm"));
            ClearCanvas.ImageViewer.ImageViewerComponent viewer = null;
            DesktopWindow desktopWindow = null;
            List <string> _filenames    = new List <string>();

            foreach (DesktopWindow window in Application.DesktopWindows)
            {
                foreach (Workspace space in window.Workspaces)
                {
                    if (space.Title == "imageview")
                    {
                        desktopWindow = window;
                        viewer        = space.Component as ClearCanvas.ImageViewer.ImageViewerComponent;
                    }
                }
            }
            if (viewer != null)
            {
                //foreach (string strfile in viewer.getCurrentFiles())
                //    _storageScu.AddFile(strfile);
                //先解压缩,然后再发送
                //foreach (string strfile in viewer.getCurrentFiles())
                //    _storageScu.AddFile(strfile);


                RasterSupport.Unlock(RasterSupportType.Dicom, "y47S3rZv6U");
                RasterSupport.Unlock(RasterSupportType.Document, "HbQR9NSXQ3");
                RasterSupport.Unlock(RasterSupportType.DocumentWriters, "BhaNezSEBB");
                RasterSupport.Unlock(RasterSupportType.DocumentWritersPdf, "3b39Q3YMdX");
                RasterSupport.Unlock(RasterSupportType.ExtGray, "bpTmxSfx8R");
                RasterSupport.Unlock(RasterSupportType.Forms, "GpC33ZK78k");
                RasterSupport.Unlock(RasterSupportType.IcrPlus, "9vdKEtBhFy");
                RasterSupport.Unlock(RasterSupportType.IcrProfessional, "3p2UAxjTy5");
                RasterSupport.Unlock(RasterSupportType.J2k, "Hvu2PRAr3z");
                RasterSupport.Unlock(RasterSupportType.Jbig2, "43WiSV4YNB");
                RasterSupport.Unlock(RasterSupportType.Jpip, "YbGG7wWiVJ");
                RasterSupport.Unlock(RasterSupportType.Pro, "");
                RasterSupport.Unlock(RasterSupportType.LeadOmr, "J3vh828GC8");
                RasterSupport.Unlock(RasterSupportType.MediaWriter, "TpjDw2kJD2");
                RasterSupport.Unlock(RasterSupportType.Medical, "ZhyFRnk3sY");
                RasterSupport.Unlock(RasterSupportType.Medical3d, "DvuzH3ePeu");
                RasterSupport.Unlock(RasterSupportType.MedicalNet, "b4nBinY7tv");
                RasterSupport.Unlock(RasterSupportType.MedicalServer, "QbXwuZxA3h");
                RasterSupport.Unlock(RasterSupportType.Mobile, "");
                RasterSupport.Unlock(RasterSupportType.Nitf, "G37rmw5dTr");
                DicomEngine.Startup();

                foreach (string strfile in viewer.getCurrentFiles())
                {
                    DicomDataSet ds = new DicomDataSet();

                    try
                    {
                        ds.Load(strfile, DicomDataSetLoadFlags.None);
                        ds.ChangeTransferSyntax(DicomUidType.ImplicitVRLittleEndian, 2, ChangeTransferSyntaxFlags.None);
                        ds.Save(strfile + "1", DicomDataSetSaveFlags.None);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(ex.ToString());
                    }
                    _storageScu.AddFile(strfile + "1");
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("没有合适的图像。。。");
            }
            IAsyncResult asyncResult = _storageScu.BeginSend(new AsyncCallback(SendComplete), _storageScu);
        }
Exemplo n.º 4
0
        private void Change_Click(object sender, EventArgs e)
        {
            // Some sanity checks !
            if (txtInFile.Text.Length == 0)
            {
                MessageBox.Show("Please enter a valid input file name ");
                return;
            }

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

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

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

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

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

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

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

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

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

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

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

                return;
            }

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

            DicomEngine.Shutdown();

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

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