コード例 #1
0
ファイル: DICOMLoad.cs プロジェクト: blackhawk1990/MUCalc
        public Dataset Load(FileInfo file)
        {
            Stream ins = null;
            DcmParser parser = null;
            Dataset ds = null;

            try
            {
                try
                {
                    ins = new BufferedStream(new FileStream(file.FullName, FileMode.Open, FileAccess.Read));
                    parser = new DcmParser(ins);
                    FileFormat format = parser.DetectFileFormat();
                    if (format != null)
                    {
                        ds = new Dataset();
                        parser.DcmHandler = ds.DcmHandler;
                        parser.ParseDcmFile(format, Tags.PixelData);

                        //MessageBox.Show("Pomyślnie!");

                        return ds;
                    }
                    else
                    {
                        //MessageBox.Show("failed!");
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.StackTrace);
                }
            }
            finally
            {
                if (ins != null)
                {
                    try
                    {
                        ins.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }

            return null;
        }
コード例 #2
0
ファイル: BasicSCU.cs プロジェクト: sleighter/dicom-sharp
        /// <summary>
        /// Perform a WADO-GET
        /// </summary>
        public Dataset WADOGet(string url, string studyInstanceUID, string seriesInstanceUID, string sopInstanceUID)
        {
            if ((studyInstanceUID != null)
            &&	(seriesInstanceUID == null)
            ||	(sopInstanceUID == null))
            {
                if (seriesInstanceUID == null)
                {
                    Dataset[] ds = CFindSeries(studyInstanceUID, null);
                    if ((ds != null)
                    &&  (ds.Length == 1))
                    {
                        seriesInstanceUID = ds[0].GetString(Tags.SeriesInstanceUID);
                    }
                }

                if (seriesInstanceUID != null)
                {
                    Dataset[] ds = CFindInstance(seriesInstanceUID);
                    if ((ds != null)
                    &&  (ds.Length == 1))
                    {
                        sopInstanceUID = ds[0].GetString(Tags.SOPInstanceUID);
                    }
                }
            }

            if ((url == null)
            ||	(studyInstanceUID == null)
            ||	(seriesInstanceUID == null)
            ||	(sopInstanceUID == null)
            ||	(url.IndexOf('?') >= 0))
                return null;

            Dataset ret = null;
            System.Net.WebResponse response = null;

            try
            {
                StringBuilder sb = new StringBuilder(url);

                sb.Append("?requestType=WADO&studyUID=");
                sb.Append(System.Web.HttpUtility.UrlEncode(studyInstanceUID));
                sb.Append("&seriesUID=");
                sb.Append(System.Web.HttpUtility.UrlEncode(seriesInstanceUID));
                sb.Append("&objectUID=");
                sb.Append(System.Web.HttpUtility.UrlEncode(sopInstanceUID));

                System.Net.WebRequest request = System.Net.WebRequest.Create(sb.ToString());

                response = request.GetResponse();

                if (string.Compare(response.ContentType, "application/dicom") == 0)
                {
                    DcmParser parser = new DcmParser(response.GetResponseStream());

                    FileFormat format = parser.DetectFileFormat();
                    if (format != null)
                    {
                        ret = new Dataset();
                        parser.DcmHandler = ret.DcmHandler;
                        parser.ParseDcmFile(format, Tags.PixelData);
                    }
                }
            }
            finally
            {
                if (response != null)
                    response.Close();
            }

            return ret;
        }
コード例 #3
0
ファイル: LoadDcmFile.cs プロジェクト: sleighter/dicom-sharp
        public void Load( FileInfo file )
        {
            Stream ins = null;
            DcmParser parser = null;
            Dataset ds = null;

            try
            {
                try
                {
                    ins = new BufferedStream(new FileStream(file.FullName, FileMode.Open, FileAccess.Read));
                    parser = new DcmParser(ins);
                    FileFormat format = parser.DetectFileFormat();
                    if (format != null)
                    {
                        ds = new Dataset();
                        parser.DcmHandler = ds.DcmHandler;
                        parser.ParseDcmFile(format, Tags.PixelData);

                        Console.WriteLine( "success!" );
                    }
                    else
                    {
                        Console.WriteLine( "failed!" );
                    }
                }
                catch( Exception e)
                {
                    Console.WriteLine( e.StackTrace );
                }
            }
            finally
            {
                if (ins != null)
                {
                    try
                    {
                        ins.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }
        }