public void GetPixelData(PrintScu.ImageBox imageBox, ColorMode colorMode, out ushort rows, out ushort columns, out byte[] pixelData) { try { ExportImageItem exportImageItem = new ExportImageItem { printItem = this }; Frame frame = ((IImageSopProvider)this.PresentationImage).Frame; object[] args = new object[3]; args[0] = imageBox.ImageBoxPosition; args[1] = colorMode; args[2] = frame.SopInstanceUid; Platform.Log(LogLevel.Debug, "PresentationImage", args); if (this.ExportOption == ExportOption.TrueSize) { imageBox.RequestedDecimateCropBehavior = DecimateCropBehavior.Crop; } else { imageBox.RequestedDecimateCropBehavior = DecimateCropBehavior.Decimate; } ExportImageParams exportImageParams = new ExportImageParams(); exportImageParams.Dpi = imageBox.FilmBox.FilmDPI; exportImageParams.SizeMode = SizeMode.ScaleToFit; exportImageParams.DisplayRectangle = this.DisplayRectangle; exportImageParams.OutputSize = imageBox.SizeInPixels; exportImageParams.ExportOption = ExportOption.Wysiwyg; exportImageItem.exportImageParams = exportImageParams; Platform.Log(LogLevel.Debug, "OutputSize", exportImageItem.exportImageParams.OutputSize); exportImageItem.bitmap = null; MemoryManager.Execute(exportImageItem.ExportImage); rows = (ushort)exportImageItem.bitmap.Size.Height; columns = (ushort)exportImageItem.bitmap.Size.Width; if (this.ExportOption == ExportOption.TrueSize) { imageBox.RequestedImageSize = (((float)columns) * 25.4f) / ((float)imageBox.FilmBox.FilmDPI); Platform.Log(LogLevel.Debug, "RequestedImageSize", imageBox.RequestedImageSize); } pixelData = BitMapUtility.GetBitmap(exportImageItem.bitmap, colorMode); } catch (Exception exception) { Platform.Log(LogLevel.Error, exception); throw; } finally { Platform.Log(LogLevel.Debug, "finally", new object[] { "完成" }); } }
private static IPresentationImage CreateResultImage(Bitmap bitmap, ColorMode colorMode, string filePath) { DicomFile file = new DicomFile(); file.DataSet[DicomTags.BitsAllocated].SetInt32(0, 8); file.DataSet[DicomTags.BitsStored].SetInt32(0, 8); file.DataSet[DicomTags.HighBit].SetInt32(0, 7); file.DataSet.RemoveAttribute(DicomTags.WindowCenter); file.DataSet.RemoveAttribute(DicomTags.WindowWidth); file.DataSet[DicomTags.PixelSpacing].SetInt32(0, 0); file.DataSet[DicomTags.RescaleIntercept].SetInt32(0, 0); file.DataSet[DicomTags.RescaleSlope].SetInt32(0, 1); file.DataSet[DicomTags.Rows].SetInt32(0, bitmap.Height); file.DataSet[DicomTags.Columns].SetInt32(0, bitmap.Width); file.DataSet[DicomTags.PixelRepresentation].SetInt32(0, 0); file.DataSet[DicomTags.NumberOfFrames].SetInt32(0, 1); file.DataSet[DicomTags.PhotometricInterpretation].SetStringValue("MONOCHROME2"); file.DataSet[DicomTags.SopClassUid].SetStringValue("1.2.840.10008.5.1.4.1.1.7"); file.DataSet[DicomTags.Modality].SetStringValue("OT"); file.DataSet[DicomTags.TransferSyntaxUid].SetStringValue("1.2.840.10008.1.2"); file.DataSet[DicomTags.StudyId].SetStringValue("1"); file.DataSet[DicomTags.StudyInstanceUid].SetStringValue("1.2.276.0.7230010.3.1.2.2866517296.296.1377417571.2"); file.DataSet[DicomTags.SeriesNumber].SetInt32(0, 1); file.DataSet[DicomTags.SamplesPerPixel].SetInt32(0, 1); file.DataSet[DicomTags.SeriesInstanceUid].SetStringValue(" 1.2.276.0.7230010.3.1.3.2866517296.296.1377417571.3"); file.DataSet[DicomTags.SopInstanceUid].SetStringValue(DicomUid.GenerateUid().UID); file.DataSet[DicomTags.PixelData].Values = null; byte[] pixelData = BitMapUtility.GetBitmap(bitmap, colorMode); file.DataSet[DicomTags.PixelData].Values = pixelData; file.MediaStorageSopClassUid = file.DataSet[DicomTags.SopClassUid]; file.MediaStorageSopInstanceUid = file.DataSet[DicomTags.SopInstanceUid]; string fileName = string.Format("{0}\\{1}", filePath, DateTime.Now.Ticks.ToString()); file.Save(fileName); var dataSource = new LocalSopDataSource(file); Sop dstSop = Sop.Create(dataSource); IPresentationImage presentation = (PresentationImageFactory.Create((ImageSop)dstSop))[0]; if (presentation is IAnnotationLayoutProvider) { foreach (AnnotationBox box in ((IAnnotationLayoutProvider)presentation).AnnotationLayout.AnnotationBoxes) { box.Visible = false; } } return(presentation); }