SetBulkData(RasterImage,int) Method (original) (raw)

Summary

Sets the BulkData with a RasterImage and a quality factor.

Syntax

Parameters

QualityFactor

A value indicating the quality factor (2..255) of the BulkData.

Remarks

There are four ways to modify the BulkData:

  1. Setting the BulkData property
  2. Calling [SetBulkData(byte[])] with a byte array
  3. Calling SetBulkData(RasterImage,int) with a RasterImage and a quality factor
  4. Calling SetBulkData(Stream) with Stream

When setting the BulkData using (3) SetBulkData(RasterImage,int), a quality factor is specified from 2 to 255 where 2 is the highest quality, and 255 is the lowest quality.

Example

using Leadtools.Dicom; using Leadtools.Dicom.Common; using Leadtools.Dicom.Common.Extensions; using Leadtools; using Leadtools.Dicom.Common.Linq.BasicDirectory; using Leadtools.Dicom.Common.DataTypes; using Leadtools.Codecs; public static class SetBulkDataExample { public static bool MyLoadJsonBeforeElementCallback(LoadJsonBeforeElementData elementData) { // You can change the TransferSyntax here to any valid TransferSyntax // Setting the TransferSyntax ElementValue to empty defaults the transfer syntax to Explicit VR Little Endian //if (elementData.Tag == DicomTag.TransferSyntaxUID) //{ // elementData.ElementValue = string.Empty; //} if (elementData.Encoding == ElementDataType.BulkData) { // If elementData.Encoding is ElementDataType.BulkData, then the BulkDataUri is returned in elementData.ElementValue Console.WriteLine($"BulkDataUri: {elementData.ElementValue}"); // Set the bulk data: four ways to do it // string rawImagePath = Path.Combine(LEAD_VARS.ImagesDir, "image2.jpg"); string pngImagePath = Path.Combine(LEAD_VARS.ImagesDir, "PngImage.png"); // Method 1: Setting the [BulkData] property using (FileStream fs = new FileStream(rawImagePath, FileMode.Open)) { using (MemoryStream ms = new MemoryStream()) { fs.CopyTo(ms); elementData.BulkData = ms.ToArray(); } } // Method 2: Calling SetBulkData() with a byte array using (FileStream fs = new FileStream(rawImagePath, FileMode.Open)) { using (MemoryStream ms = new MemoryStream()) { fs.CopyTo(ms); elementData.SetBulkData(ms.ToArray()); } } // Method 3 // Set the bulk data using a RasterImage using (RasterCodecs codecs = new RasterCodecs()) { using (Leadtools.RasterImage image = codecs.Load(pngImagePath)) { // The second argument is optional and specifies the QFactor elementData.SetBulkData(image, 2); } } // Method 4 // In this example(image2.dcm) it is raw jpeg data // For uncompressed DICOM data, pass the raw uncompressedData using (FileStream fs = new FileStream(rawImagePath, FileMode.Open)) { elementData.SetBulkData(fs); } } return true; } public static void MyLoadJson() { string dicomPath = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "image2.dcm"); string jsonPath = Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "image2.json"); using (DicomDataSet dsJson = new DicomDataSet()) { dsJson.Load(dicomPath, DicomDataSetLoadFlags.None); dsJson.SaveJson(jsonPath, DicomDataSetSaveJsonFlags.IgnoreBinaryData); } using (DicomDataSet ds = new DicomDataSet()) { ds.LoadJson(jsonPath, DicomDataSetLoadJsonFlags.None, MyLoadJsonBeforeElementCallback, null); } } } static class LEAD_VARS { public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; }

Requirements

Target Platforms

See Also

LoadBeforeElementData Class

LoadBeforeElementData Members

Leadtools.Dicom.Common.Extensions Namespace

[SetBulkData(byte[])]:../dco/Extensions-LoadBeforeElementData-SetBulkData(byte[]).md

Leadtools.Dicom.Common Assembly