Ejemplo n.º 1
0
 private void OnProcessingJPEG(ConvertProcessEventArgs e)
 {
     if (this.ProcessingAVI != null)
     {
         this.ProcessingAVI(this, e);
     }
 }
Ejemplo n.º 2
0
        void ExtractMultiframes2Singleframe(object o)
        {
            float nPercent             = 0;
            ConvertProcessEventArgs ev = new ConvertProcessEventArgs(0);

            JpegFileList.Clear();
            if (!File.Exists(SourceFileName))
            {
                return;
            }

            DicomFile    dcmFile    = DicomFile.Open(SourceFileName);
            DicomDataset dcmDataset = dcmFile.Dataset;
            int          frames     = dcmFile.Dataset.Get <int>(DicomTag.NumberOfFrames);

            if (frames == 0)
            {
                frames = 1;
            }

            string srcName = Path.GetFileName(SourceFileName);
            string tmpPath = AppDomain.CurrentDomain.BaseDirectory + "tmpframe\\";

            if (!Directory.Exists(tmpPath))
            {
                Directory.CreateDirectory(tmpPath);
            }
            else
            {
                DeleteDir(tmpPath);
            }

            for (int i = 0; i < frames; i++)
            {
                try
                {
                    DicomFile  tmpFile        = dcmFile.Clone();
                    string     sopinstanceuid = tmpFile.Dataset.Get <string>(DicomTag.SOPInstanceUID, "");
                    DicomImage dcmSingleImg   = new DicomImage(tmpFile.Dataset);

                    Image  img        = dcmSingleImg.RenderImage(i);
                    string tmpJpgName = string.Format(sopinstanceuid + "-{0}.jpg", i.ToString().PadLeft(5, '0'), tmpPath);
                    tmpJpgName = tmpPath + tmpJpgName;
                    if (img != null)
                    {
                        img.Save(tmpJpgName);
                    }
                    JpegFileList.Add(tmpJpgName);
                    nPercent = (i + 1.0f) / frames * 100;
                    string s = nPercent.ToString(("#.##"));
                    callback(nPercent);
                    Thread.Sleep(1);
                }
                catch (Exception e)
                {
                    //MessageBox.Show(string.Format("Errors:{0},Details:{1}", e.Message + e.StackTrace));
                }

                ev.Percent = 100;
            }
        }
Ejemplo n.º 3
0
        void ConvertDicom2AVIFormat(object o)
        {
            float nPercent             = 0;
            ConvertProcessEventArgs ev = new ConvertProcessEventArgs(0);

            #region 多帧文件存在

            if (File.Exists(strMultiFrameDicomFileName))
            {
                AVIWriter aviWriter = new AVIWriter();

                DicomFile dcmFile = DicomFile.Open(strMultiFrameDicomFileName);


                dcmFile.Dataset.Get <string>(DicomTag.SOPInstanceUID, "");

                int bmWidth  = Convert.ToInt16(dcmFile.Dataset.Get <string>(DicomTag.Columns, ""));
                int bmHeight = Convert.ToInt16(dcmFile.Dataset.Get <string>(DicomTag.Rows, ""));

                string strDestFile = strOutPutAVIName;

                aviWriter.Create(strDestFile, (UInt16)nFrs, bmWidth, bmHeight);

                try
                {
                    for (int i = nBeginFrame; i < nEndFrame; i++)
                    {
                        DicomFile  tmpFile      = dcmFile.Clone();
                        DicomImage dcmSingleImg = new DicomImage(tmpFile.Dataset);
                        Image      img          = dcmSingleImg.RenderImage(i);
                        Bitmap     bmp          = new Bitmap(img);
                        bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
                        aviWriter.LoadFrame(bmp);
                        aviWriter.AddFrame();
                        if (nEndFrame == 0)
                        {
                            nEndFrame = Convert.ToInt16(dcmFile.Dataset.Get <string>(DicomTag.NumberOfFrames, ""));
                        }
                        float f = (float)100 / (float)nEndFrame - nBeginFrame;
                        nPercent += f;
                        string s = nPercent.ToString(("#.##"));
                        ev.LastPercent = ev.Percent;
                        ev.Percent     = Convert.ToSingle(s);
                        callback(nPercent);
                        Thread.Sleep(1);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
                finally
                {
                    aviWriter.Close();
                }
            }
            #endregion

            #region 单帧文件列表存在

            if (listSingleFrameFileName.Count > 0)
            {
                AVIWriter aviWriter = new AVIWriter();

                DicomFile tmp_dcmFile = DicomFile.Open(listSingleFrameFileName[0]);

                int bmWidth  = Convert.ToInt16(tmp_dcmFile.Dataset.Get <string>(DicomTag.Columns, ""));
                int bmHeight = Convert.ToInt16(tmp_dcmFile.Dataset.Get <string>(DicomTag.Rows, ""));


                string strDestFile = strOutPutAVIName;

                aviWriter.Create(strDestFile, (UInt16)nFrs, bmWidth, bmHeight);

                try
                {
                    for (int i = 0; i < listSingleFrameFileName.Count; i++)
                    {
                        tmp_dcmFile = DicomFile.Open(listSingleFrameFileName[0]);
                        DicomFile  tmpFile      = tmp_dcmFile.Clone();
                        DicomImage dcmSingleImg = new DicomImage(tmpFile.Dataset);
                        Image      img          = dcmSingleImg.RenderImage(0);
                        Bitmap     bmp          = new Bitmap(img);
                        bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
                        aviWriter.LoadFrame(bmp);
                        aviWriter.AddFrame();
                        float f = (float)100 / (float)listSingleFrameFileName.Count;
                        nPercent += f;
                        string s = nPercent.ToString(("#.##"));
                        ev.LastPercent = ev.Percent;
                        ev.Percent     = Convert.ToSingle(s);
                        callback(nPercent);
                        Thread.Sleep(1);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                }
                finally
                {
                    aviWriter.Close();
                }

                #endregion
            }

            ev.Percent = 100;
        }