Exemplo n.º 1
0
            internal void BeforeSet(ColorMode colorMode)
            {
                byte[] pixelData;
                ushort rows;
                ushort columns;

                if (colorMode == ColorMode.Color)
                {
                    var image = new BasicColorImageSequenceIod
                    {
                        SamplesPerPixel           = 3,
                        PhotometricInterpretation = PhotometricInterpretation.Rgb,
                        PixelRepresentation       = 0,
                        PixelAspectRatio          = new PixelAspectRatio(1, 1),
                        PlanarConfiguration       = 0,
                        BitsStored    = 8,
                        BitsAllocated = 8,
                        HighBit       = 7
                    };

                    this.PrintItem.GetPixelData(this, colorMode, out rows, out columns, out pixelData);
                    image.PixelData = pixelData;
                    image.Rows      = rows;
                    image.Columns   = columns;

                    this.BasicColorImageSequenceList.Add(image);
                }
                else
                {
                    var image = new BasicGrayscaleImageSequenceIod
                    {
                        SamplesPerPixel           = 1,
                        PhotometricInterpretation = PhotometricInterpretation.Monochrome2,
                        PixelRepresentation       = 0,
                        PixelAspectRatio          = new PixelAspectRatio(1, 1),
                        BitsStored    = 8,
                        BitsAllocated = 8,
                        HighBit       = 7
                    };

                    this.PrintItem.GetPixelData(this, colorMode, out rows, out columns, out pixelData);
                    image.PixelData = pixelData;
                    image.Rows      = rows;
                    image.Columns   = columns;

                    this.BasicGrayscaleImageSequenceList.Add(image);
                }
            }
Exemplo n.º 2
0
        private void InternalPrint(PrintJob job)
        {
            BasicFilmSessionModuleIod basicFilmSessionModuleIod = new BasicFilmSessionModuleIod
            {
                NumberOfCopies  = job.Copies,
                MediumType      = job.MediumType,
                FilmDestination = job.FilmDestination
            };
            BasicFilmBoxModuleIod basicFilmBoxModuleIod = new BasicFilmBoxModuleIod
            {
                //ImageDisplayFormat = @"STANDARD\1,1",
                ImageDisplayFormat    = ImageDisplayFormat.Standard_1x1,
                FilmSizeId            = job.FilmSize,
                Illumination          = job.Illumination,
                FilmOrientation       = job.FilmOrientation,
                ReflectedAmbientLight = job.ReflectedAmbientLight,
                MagnificationType     = job.MagnificationType
            };
            IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods = new List <ImageBoxPixelModuleIod>();
            bool           userCancelled = false;
            BackgroundTask task          = new BackgroundTask(delegate(IBackgroundTaskContext context)
            {
                try
                {
                    BackgroundTaskProgress progress;
                    ushort num  = 1;
                    int percent = 0;
                    new List <string>();
                    ImageBoxPixelModuleIod item = new ImageBoxPixelModuleIod
                    {
                        ImageBoxPosition = 1
                    };
                    BasicGrayscaleImageSequenceIod iod2 = new BasicGrayscaleImageSequenceIod
                    {
                        PhotometricInterpretation = job.MonochormeType
                    };
                    Size size    = this.CalcMaxSize(job.Format, job.Images);
                    Bitmap image = new Bitmap(size.Width, size.Height);
                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
                    foreach (PreviewTile tile in job.Images)
                    {
                        percent  = (int)((((float)(num - 1)) / ((float)job.Images.Count)) * 80f);
                        num      = (ushort)(num + 1);
                        progress = new BackgroundTaskProgress(percent, string.Format(SR.CreatingImageBuffer, num, job.Images.Count));
                        context.ReportProgress(progress);
                        if (tile.ImageData != null)
                        {
                            Platform.Log(LogLevel.Error, "TITLE IMAGEDATA");
                            Bitmap printImagePixel = tile.GetPrintImagePixel(false);
                            float x      = tile.NormalizedRectangle.X * size.Width;
                            float y      = tile.NormalizedRectangle.Y * size.Height;
                            float width  = tile.NormalizedRectangle.Width * size.Width;
                            float height = tile.NormalizedRectangle.Height * size.Height;
                            g.DrawImage(printImagePixel, x, y, width, height);
                            g.DrawRectangle(Pens.White, x, y, width, height);
                            Rectangle destination = new Rectangle(((int)x) + 2, ((int)y) + 2, ((int)width) - 4, ((int)height) - 4);
                            try
                            {
                                IconCreator.DrawTextOverlay(g, destination, tile.ImageData);
                            }
                            catch (Exception ex)
                            {
                                Platform.Log(LogLevel.Error, " exception: " + ex.ToString());
                            }
                            printImagePixel.Dispose();
                            if (context.CancelRequested)
                            {
                                userCancelled = true;
                                break;
                            }
                        }
                    }

                    //clear
                    foreach (PreviewTile tile in job.Images)
                    {
                        ImageSop sop  = ((IImageSopProvider)tile.ImageData).ImageSop;
                        string strUID = sop.SopInstanceUid;
                        //获取UID 的 accession
                        try
                        {
                            if (Conn.isOracle())
                            {
                                string sqlstr = string.Format(" update examrecord set filmprint='{0}' where  id=(select AccessionNumber from images where SopInstanceUID='{1}') and modulename='RIS' ",
                                                              "1", strUID);
                                OracleCommand sqlCmd = new OracleCommand();
                                sqlCmd.Connection    = GlobalData.MainConn.ChangeTypeOracle();
                                sqlCmd.CommandText   = sqlstr;
                                sqlCmd.ExecuteNonQuery();
                                sqlCmd.Dispose();
                            }
                            else
                            {
                                string sqlstr = string.Format(" update examrecord set filmprint='{0}' where  id=(select AccessionNumber from images where SopInstanceUID='{1}') and modulename='RIS' ",
                                                              "1", strUID);
                                SqlCommand sqlCmd  = new SqlCommand();
                                sqlCmd.Connection  = GlobalData.MainConn.ChangeType();
                                sqlCmd.CommandText = sqlstr;
                                sqlCmd.ExecuteNonQuery();
                                sqlCmd.Dispose();
                                Platform.Log(LogLevel.Error, " sql is  " + sqlstr);
                            }
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Error, "exception is " + ex.ToString());
                        }
                        //tile.Dispose();
                        tile.RemoveImage();
                    }

                    job.Images.Clear();


                    g.Dispose();
                    //iod2.AddBitmap(image);
                    Unlock();
                    RasterImage lRasterImage   = null;
                    RasterCodecs lRasterCodecs = new RasterCodecs();

                    lRasterImage = RasterImageConverter.ConvertFromImage(image, ConvertFromImageOptions.None);
                    lRasterCodecs.Save(lRasterImage, System.Windows.Forms.Application.StartupPath + @"\print.jpg", RasterImageFormat.Tif, 8);
                    string lDicomFile = "1" + DateTime.Now.ToString("HHmmss", DateTimeFormatInfo.InvariantInfo);
                    lRasterCodecs.Save(lRasterImage, System.Windows.Forms.Application.StartupPath + @"\PrintFiles\" + lDicomFile, RasterImageFormat.DicomGray, 16);
                    //image.Save("d:\\test.jpg");
                    image.Dispose();
                    lRasterImage.Dispose();
                    lRasterCodecs.Dispose();
                    //item.BasicGrayscaleImageSequenceList.Add(iod2);
                    //imageBoxPixelModuleIods.Add(item);
                    if (userCancelled)
                    {
                        Platform.Log(LogLevel.Info, SR.UserCancel);
                    }
                    else
                    {
                        progress = new BackgroundTaskProgress(80, SR.BeginSendImage);
                        context.ReportProgress(progress);
                        PrintDicomFiles(lDicomFile, 1, 1, lDicomFile, job);

                        //BasicGrayscalePrintScu scu = new BasicGrayscalePrintScu();
                        //scu.Print(job.Printer.AET, job.Printer.CalledAET, job.Printer.Host, job.Printer.Port, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods);
                        //if (scu.ResultStatus == DicomState.Success)
                        //{
                        //    this.UpdateStudyPrintStatus(this.GetStudyInstanceUIDs(job.Images));
                        //    PrintToolComponent.TilesComponent.ResetTiles();
                        //}
                        //else
                        //{
                        //    this._component.ShowMessageBox(SR.FilmError);
                        //}
                    }
                }
                catch (OutOfMemoryException)
                {
                    Platform.Log(LogLevel.Error, "内存不够");
                    BackgroundTaskProgress progress2 = new BackgroundTaskProgress(100, SR.OutOfMemory);
                    context.ReportProgress(progress2);
                    this._component.ShowMessageBox(SR.OutOfMemory);
                }
                catch (Exception exception)
                {
                    Platform.Log(LogLevel.Error, exception.Message);
                    BackgroundTaskProgress progress3 = new BackgroundTaskProgress(100, exception.Message);
                    context.ReportProgress(progress3);
                    this._component.ShowMessageBox(SR.PrinterError);
                }
                finally
                {
                    context.Complete(null);
                }
            }, true);

            ProgressDialog.Show(task, this._window, true, ProgressBarStyle.Blocks);
        }
Exemplo n.º 3
0
 private bool GoPrint(PrintJob printJob, out int successSend)
 {
     successSend = 0;
     try
     {
         BasicFilmSessionModuleIod basicFilmSessionModuleIod = new BasicFilmSessionModuleIod
         {
             NumberOfCopies  = printJob.Copies,
             MediumType      = printJob.MediumType,
             FilmDestination = printJob.FilmDestination
         };
         BasicFilmBoxModuleIod basicFilmBoxModuleIod = new BasicFilmBoxModuleIod
         {
             //ImageDisplayFormat = printJob.Format,
             FilmSizeId            = printJob.FilmSize,
             Illumination          = printJob.Illumination,
             FilmOrientation       = printJob.FilmOrientation,
             ReflectedAmbientLight = printJob.ReflectedAmbientLight,
             MagnificationType     = printJob.MagnificationType
         };
         IList <ImageBoxPixelModuleIod> imageBoxPixelModuleIods = new List <ImageBoxPixelModuleIod>();
         ushort num = 1;
         foreach (PreviewTile tile in printJob.Images)
         {
             this.ChangeSendStatus(printJob.ID, string.Format(SR.CreatingImageBuffer, num, printJob.Images.Count));
             ImageBoxPixelModuleIod item = new ImageBoxPixelModuleIod
             {
                 ImageBoxPosition = tile.Position
             };
             BasicGrayscaleImageSequenceIod iod4 = new BasicGrayscaleImageSequenceIod
             {
                 PhotometricInterpretation = printJob.MonochormeType
             };
             Bitmap printImagePixel = tile.GetPrintImagePixel(true);
             iod4.AddBitmap(printImagePixel);
             printImagePixel.Dispose();
             item.BasicGrayscaleImageSequenceList.Add(iod4);
             imageBoxPixelModuleIods.Add(item);
         }
         if (this.StopKey)
         {
             return(false);
         }
         this.ChangeSendStatus(printJob.ID, SR.BeginSendImage);
         try
         {
             for (int i = 0; i < printJob.Copies; i++)
             {
                 BasicGrayscalePrintScu scu = new BasicGrayscalePrintScu();
                 this.ChangeSendStatus(printJob.ID, string.Format(SR.Sending, i.ToString(), printJob.Copies.ToString()));
                 if (scu.Print(printJob.Printer.AET, printJob.Printer.CalledAET, printJob.Printer.Host, printJob.Printer.Port, basicFilmSessionModuleIod, basicFilmBoxModuleIod, imageBoxPixelModuleIods) == DicomState.Success)
                 {
                     successSend++;
                 }
             }
         }
         catch (Exception exception)
         {
             Platform.Log(LogLevel.Error, exception);
         }
     }
     catch (Exception exception2)
     {
         Platform.Log(LogLevel.Error, exception2);
     }
     if (successSend == 0)
     {
         return(false);
     }
     return(true);
 }