public void SetImage(IPresentationImage pImage, RectangleF range) { this.RemovePresentImage(); this._range = range; this._imageData = pImage; this._icon = IconCreator.CreatePresentationImageIcon(this._imageData, this._range, this._tileRatio); EventsHelper.Fire(this._OnImageChanged, this, EventArgs.Empty); }
public Bitmap GetPrintImagePixel(bool withAnnotation) { if (this._range != Rectangle.Empty) { Platform.Log(LogLevel.Error, "this._range != Rectangle.Empty"); return(IconCreator.CreatePresentationImagePrintData(this._imageData, this._range, this._tileRatio, 1f, withAnnotation)); } return(IconCreator.CreatePresentationImagePrintData(this._imageData, this._tileRatio, withAnnotation)); }
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); }