Пример #1
0
        /// <summary>
        /// Print Page event
        /// </summary>
        private void _printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            int savePage = _viewer.Image.Page;

            try
            {
                _viewer.Image.Page = _printPage;
                _printPage++;

                using (Image img = RasterImageConverter.ConvertToImage(_viewer.Image, ConvertToImageOptions.None))
                {
                    if (DialogUtilities.CanRunPrintPreview)
                    {
                        e.Graphics.DrawImage(img, 0, 0);
                    }
                }

                e.HasMorePages = _printPage <= _viewer.Image.PageCount;
                if (_printPage > _viewer.Image.PageCount)
                {
                    _printPage = 1;
                }
            }
            finally
            {
                _viewer.Image.Page = savePage;
            }
        }
Пример #2
0
        private ImageSource GetThumbnail()
        {
            RasterImage image       = Image.CreateThumbnail(200, 200, 24, RasterViewPerspective.BottomLeft, RasterSizeFlags.None);
            var         imageSource = RasterImageConverter.ConvertToSource(image, ConvertToSourceOptions.None);

            return(imageSource);
        }
Пример #3
0
        public static RasterImage FromImageToRasterImage(this IImage image)
        {
            var imageSource = image.ToBgr().ToBitmapSource();

            imageSource.Freeze();
            return(RasterImageConverter.ConvertFromSource(imageSource, ConvertFromSourceOptions.None));
        }
Пример #4
0
 private static void OnImageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is ImageViewer imageViewer && e.NewValue is ImageSource imageSource)
     {
         imageViewer.Image = RasterImageConverter.ConvertFromSource(imageSource, ConvertFromSourceOptions.AutoDetectAlpha);
     }
 }
        private RasterImage CreateAttachmentImage(ImageViewer imageViewer)
        {
            // Get the attachment image from the resource
            Bitmap icon = Properties.Resources.Attachment;

            using (RasterImage image = RasterImageConverter.ConvertFromImage(icon, ConvertFromImageOptions.None))
            {
                // Resize the image to be the same as width as image viewer thumbnails with original height
                int desiredWidth;
                if (_documentViewer.Thumbnails != null)
                {
                    desiredWidth = _documentViewer.Thumbnails.MaximumSize.Width;
                }
                else
                {
                    desiredWidth = image.ImageWidth;
                }

                var         destRect        = new LeadRect(0, 0, desiredWidth, image.ImageHeight);
                RasterImage attachmentImage = RasterImage.Create(destRect.Width, destRect.Height, 32, 96, RasterColor.Black);
                new SetAlphaValuesCommand(0x00).Run(attachmentImage);

                LeadRect imageRect = RasterImage.CalculatePaintModeRectangle(
                    image.ImageWidth,
                    image.ImageHeight,
                    destRect,
                    RasterPaintSizeMode.Fit,
                    RasterPaintAlignMode.Center,
                    RasterPaintAlignMode.Center);

                new CombineFastCommand(attachmentImage, imageRect, LeadPoint.Empty, Leadtools.ImageProcessing.CombineFastCommandFlags.SourceCopy).Run(image);
                return(attachmentImage);
            }
        }
Пример #6
0
        public void SetDocument(PDFDocument document)
        {
            _rasterImageList.BeginUpdate();
            _bookmarksTreeView.BeginUpdate();
            _signaturesTreeView.BeginUpdate();

            _rasterImageList.Items.Clear();
            _bookmarksTreeView.Nodes.Clear();
            _signaturesTreeView.Nodes.Clear();

            // This is the image we will load till the thumbnails are loaded
            using (Bitmap loadingThumbnailBitmap = global::PDFDocumentDemo.Properties.Resources.LoadingThumbnail)
            {
                using (RasterImage itemImage = RasterImageConverter.ConvertFromImage(loadingThumbnailBitmap, ConvertFromImageOptions.None))
                {
                    if (document != null && document.Pages.Count >= 1)
                    {
                        for (int page = 1; page <= document.Pages.Count; page++)
                        {
                            // We need to clone itemImage since the image list has AutoDisposeImages set to true
                            ImageViewerItem item = new ImageViewerItem();
                            item.Image      = itemImage.Clone();
                            item.PageNumber = page;
                            item.Text       = "Page " + page.ToString();
                            _rasterImageList.Items.Add(item);
                        }
                    }
                }
            }

            // Add the bookmarks (if any)
            if (document != null && document.Bookmarks != null)
            {
                AddBookmarks(document.Bookmarks);
            }
            // Add the signatures (if any)
            if (document != null)
            {
                AddSignatures(document);
            }

            _rasterImageList.EndUpdate();
            _bookmarksTreeView.EndUpdate();
            _signaturesTreeView.EndUpdate();


            if (document != null && document.Pages.Count >= 1)
            {
                // Start reading the thumbnails
                _generateThumbnailsWorker.Start(document, _rasterImageList.GetItemImageSize(_rasterImageList.ActiveItem, true).Width, _rasterImageList.GetItemImageSize(_rasterImageList.ActiveItem, true).Height);
            }

            UpdateUIState();
        }
Пример #7
0
        void scEngine_CaptureInformation(object sender, ScreenCaptureInformationEventArgs e)
        {
            e.Image.XResolution = e.Image.YResolution = 300;
            AnnAutomationObject customAnn   = annAutomationManager.FindObjectById(AnnObject.StampObjectId);
            AnnStampObject      customStamp = (AnnStampObject)customAnn.ObjectTemplate;

            customStamp.Text = " ";

            customStamp.Fill    = null;
            customStamp.Stroke  = AnnStroke.Create(AnnSolidColorBrush.Create("Red"), LeadLengthD.Create(0));;
            customStamp.Picture = new AnnPicture(RasterImageConverter.ConvertToImage(e.Image, ConvertToImageOptions.None));
        }
Пример #8
0
        private void _btnPrint_Click(object sender, EventArgs e)
        {
            ((MainForm)this.Owner).PrintImage = RasterImageConverter.ConvertFromImage(image, ConvertFromImageOptions.None);
            RasterImage   printImage    = ((MainForm)this.Owner).PrintImage;
            PrintDocument printDocument = ((MainForm)this.Owner).PrintDocument;

            printDocument.PrinterSettings.MinimumPage = 1;
            printDocument.PrinterSettings.MaximumPage = printImage.PageCount;
            printDocument.PrinterSettings.FromPage    = 1;
            printDocument.PrinterSettings.ToPage      = printImage.PageCount;
            printDocument.Print();

            this.Close();
        }
        private static void FillSeriesThumbnail(LoadSeriesEventArgs e, SeriesInformation seriesInfo)
        {
            if (e.LoadedSeries.Streamer.SeriesCells.Length > 0)
            {
                MedicalViewerMultiCell cell = e.LoadedSeries.Streamer.SeriesCells[0];

                if (cell.VirtualImage != null)
                {
                    if (cell.VirtualImage[cell.ActiveSubCell].ImageExist)
                    {
                        using (RasterImage image = cell.VirtualImage[cell.ActiveSubCell].Image.Clone())
                        {
                            Image thumbImage;

                            if (image.Width != 64 || image.Height != 64)
                            {
                                SizeCommand sizeCommand;


                                sizeCommand = new SizeCommand(64, 64, RasterSizeFlags.None);

                                sizeCommand.Run(image);
                            }

                            if (image.BitsPerPixel != 24)
                            {
                                ColorResolutionCommand colorRes = new ColorResolutionCommand(ColorResolutionCommandMode.InPlace,
                                                                                             24,
                                                                                             RasterByteOrder.Bgr,
                                                                                             RasterDitheringMethod.None,
                                                                                             ColorResolutionCommandPaletteFlags.FastMatch,
                                                                                             null);


                                colorRes.Run(image);
                            }

                            thumbImage = RasterImageConverter.ConvertToImage(image, ConvertToImageOptions.InitAlpha);

                            seriesInfo.Thumbnail = thumbImage;
                        }
                    }
                }
            }
        }
Пример #10
0
        private void _btnSave_Click(object sender, EventArgs e)
        {
            ImageFileSaver _saver = new ImageFileSaver();

            try
            {
                using (RasterCodecs codecs = new RasterCodecs())
                {
                    using (RasterImage rasterImage = RasterImageConverter.ConvertFromImage(image, ConvertFromImageOptions.None))
                    {
                        DemosGlobal.SetDefaultComments(rasterImage, codecs);
                        _saver.Save(this, codecs, rasterImage);
                    }
                }
                this.Close();
            }
            catch (Exception ex)
            {
                Messager.ShowFileSaveError(this, _saver.FileName, ex);
            }
        }
Пример #11
0
        private void PostSetPageThumbnail(Workers.ThreadedPageWorkerPageProcessedEventArgs e)
        {
            int itemIndex = e.PageNumber - 1;

            if (itemIndex >= 0 && itemIndex < _rasterImageList.Items.Count)
            {
                ImageViewerItem item = _rasterImageList.Items[itemIndex];

                RasterImage image = e.Data as RasterImage;
                if (image == null || e.Error != null)
                {
                    // Could no be loaded
                    using (Bitmap loadingThumbnailBitmap = global::PDFDocumentDemo.Properties.Resources.ErrorThumbnail)
                    {
                        image = RasterImageConverter.ConvertFromImage(loadingThumbnailBitmap, ConvertFromImageOptions.None);
                    }
                }

                item.Image = image;
                _rasterImageList.Invalidate(true);
            }
        }
Пример #12
0
 public static RasterImage ToRasterImage(this ImageSource rasterImage)
 {
     return(RasterImageConverter.ConvertFromSource(rasterImage, ConvertFromSourceOptions.None));
 }
Пример #13
0
        public static IImage ToImage(this RasterImage rasterImage)
        {
            var convertToSource = (BitmapSource)RasterImageConverter.ConvertToSource(rasterImage, ConvertToSourceOptions.None);

            return(convertToSource.ToArray <Bgr <byte> >().Lock());
        }
Пример #14
0
        private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            RasterImage image = (_imageList.ActiveItem as PDFPageItem).PageImage;

            // Get the print document object
            PrintDocument document = sender as PrintDocument;

            // Create an new LEADTOOLS image printer class
            RasterImagePrinter printer = new RasterImagePrinter();

            // Set the document object so page calculations can be performed
            printer.PrintDocument = document;

            // We want to fit and center the image into the maximum print area
            printer.SizeMode            = RasterPaintSizeMode.FitAlways;
            printer.HorizontalAlignMode = RasterPaintAlignMode.Center;
            printer.VerticalAlignMode   = RasterPaintAlignMode.Center;

            // Account for FAX images that may have different horizontal and vertical resolution
            printer.UseDpi = true;

            // Print the whole image
            printer.ImageRectangle = Rectangle.Empty;

            // Use maximum page dimension ignoring the margins, this will be equivalant of printing
            // using Windows Photo Gallery
            printer.PageRectangle = RectangleF.Empty;
            printer.UseMargins    = false;

            using (Image printImage = RasterImageConverter.ConvertToImage(image, ConvertToImageOptions.None))
            {
                using (Bitmap printBitmap = new Bitmap(printImage))
                {
                    foreach (FormFieldControl control in _imageViewer.Controls)
                    {
                        if (control.IsFieldPrintable)
                        {
                            bool isFieldVisible = control.IsFieldVisible;
                            control.IsFieldVisible = true;

                            LeadRect leadBounds = new LeadRect(control.Bounds.X, control.Bounds.Y, control.FiedlBounds.Width, control.Bounds.Height);

                            // convert from Control to Image coordinates
                            leadBounds = _imageViewer.ConvertRect(null, ImageViewerCoordinateType.Control, ImageViewerCoordinateType.Image, leadBounds);

                            Rectangle bounds = new Rectangle(leadBounds.X, leadBounds.Y, leadBounds.Width, leadBounds.Height);

                            control.DrawToBitmap(printBitmap, bounds);

                            control.IsFieldVisible = isFieldVisible;
                        }
                    }

                    image = RasterImageConverter.ConvertFromImage(printBitmap, ConvertFromImageOptions.None);
                }
            }

            // Print the current page
            printer.Print(image, _currentPrintPageNumber, e);

            // Go to the next page
            _currentPrintPageNumber++;

            // Inform the printer whether we have more pages to print
            if (_currentPrintPageNumber <= document.PrinterSettings.ToPage)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
            }
        }
Пример #15
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);
        }