Class DicomImage

Class DicomImage

Namespace: Aspose.Imaging.FileFormats.Dicom
Assembly: Aspose.Imaging.dll (25.2.0)

This Class implements Digital Imaging and Communications in Medicine (DICOM) raster image format support and offers a comprehensive solution for processing DICOM images with precision and flexibility. You can seamlessly manipulate image pages, including operations to get, add, or remove pages, and control the default and active pages. With capabilities to work with alpha channels, embed XMP metadata, resize, rotate, crop, binarize, adjust, apply filters, and convert to other raster formats. This API empowers developers to handle DICOM images effectively while meeting diverse application requirements in medical imaging contexts.

[JsonObject(MemberSerialization.OptIn)]
public sealed class DicomImage : RasterCachedMultipageImage, IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata, IMultipageImageExt, IMultipageImage

Inheritance

objectDisposableObjectDataStreamSupporterImageRasterImageRasterCachedImageRasterCachedMultipageImageDicomImage

Implements

IDisposable, IObjectWithBounds, IRasterImageArgb32PixelLoader, IRasterImageRawDataLoader, IHasXmpData, IHasMetadata, IMultipageImageExt, IMultipageImage

Inherited Members

RasterCachedMultipageImage.AdjustBrightness(int), RasterCachedMultipageImage.AdjustContrast(float), RasterCachedMultipageImage.AdjustGamma(float, float, float), RasterCachedMultipageImage.AdjustGamma(float), RasterCachedMultipageImage.Blend(Point, RasterImage, Rectangle, byte), RasterCachedMultipageImage.BinarizeFixed(byte), RasterCachedMultipageImage.BinarizeBradley(double, int), RasterCachedMultipageImage.BinarizeBradley(double), RasterCachedMultipageImage.BinarizeOtsu(), RasterCachedMultipageImage.Crop(Rectangle), RasterCachedMultipageImage.Crop(int, int, int, int), RasterCachedMultipageImage.Dither(DitheringMethod, int, IColorPalette), RasterCachedMultipageImage.Grayscale(), RasterCachedMultipageImage.Rotate(float, bool, Color), RasterCachedMultipageImage.RotateFlip(RotateFlipType), RasterCachedMultipageImage.RotateFlipAll(RotateFlipType), RasterCachedMultipageImage.Resize(int, int, ResizeType), RasterCachedMultipageImage.Resize(int, int, ImageResizeSettings), RasterCachedMultipageImage.ResizeWidthProportionally(int, ResizeType), RasterCachedMultipageImage.ResizeHeightProportionally(int, ResizeType), RasterCachedMultipageImage.ReplaceColor(int, byte, int), RasterCachedMultipageImage.ReplaceNonTransparentColors(int), RasterCachedMultipageImage.Filter(Rectangle, FilterOptionsBase), RasterCachedMultipageImage.NormalizeAngle(bool, Color), RasterCachedMultipageImage.CacheData(), RasterCachedMultipageImage.GetSerializedStream(ImageOptionsBase, Rectangle, out int), RasterCachedMultipageImage.Height, RasterCachedMultipageImage.Width, RasterCachedMultipageImage.BitsPerPixel, RasterCachedMultipageImage.IsCached, RasterCachedMultipageImage.PageCount, RasterCachedMultipageImage.Pages, RasterCachedMultipageImage.HasAlpha, RasterCachedMultipageImage.HasTransparentColor, RasterCachedMultipageImage.ImageOpacity, RasterCachedMultipageImage.BackgroundColor, RasterCachedMultipageImage.XmpData, RasterCachedMultipageImage.PageExportingAction, RasterCachedImage.CacheData(), RasterCachedImage.Blend(Point, RasterImage, Rectangle, byte), RasterCachedImage.Resize(int, int, ResizeType), RasterCachedImage.Resize(int, int, ImageResizeSettings), RasterCachedImage.RotateFlip(RotateFlipType), RasterCachedImage.Rotate(float, bool, Color), RasterCachedImage.Crop(Rectangle), RasterCachedImage.Dither(DitheringMethod, int, IColorPalette), RasterCachedImage.Grayscale(), RasterCachedImage.BinarizeFixed(byte), RasterCachedImage.BinarizeOtsu(), RasterCachedImage.BinarizeBradley(double, int), RasterCachedImage.BinarizeBradley(double), RasterCachedImage.AdjustBrightness(int), RasterCachedImage.AdjustContrast(float), RasterCachedImage.AdjustGamma(float, float, float), RasterCachedImage.AdjustGamma(float), RasterCachedImage.IsCached, RasterImage.RemoveMetadata(), RasterImage.Save(Stream, ImageOptionsBase, Rectangle), RasterImage.GetModifyDate(bool), RasterImage.Dither(DitheringMethod, int), RasterImage.Dither(DitheringMethod, int, IColorPalette), RasterImage.GetDefaultPixels(Rectangle, IPartialArgb32PixelLoader), RasterImage.GetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings), RasterImage.GetDefaultArgb32Pixels(Rectangle), RasterImage.GetDefaultRawData(Rectangle, RawDataSettings), RasterImage.GetArgb32Pixel(int, int), RasterImage.GetPixel(int, int), RasterImage.SetArgb32Pixel(int, int, int), RasterImage.SetPixel(int, int, Color), RasterImage.ReadScanLine(int), RasterImage.ReadArgb32ScanLine(int), RasterImage.WriteScanLine(int, Color[]), RasterImage.WriteArgb32ScanLine(int, int[]), RasterImage.LoadPartialArgb32Pixels(Rectangle, IPartialArgb32PixelLoader), RasterImage.LoadPartialPixels(Rectangle, IPartialPixelLoader), RasterImage.LoadArgb32Pixels(Rectangle), RasterImage.LoadArgb64Pixels(Rectangle), RasterImage.LoadPartialArgb64Pixels(Rectangle, IPartialArgb64PixelLoader), RasterImage.LoadPixels(Rectangle), RasterImage.LoadCmykPixels(Rectangle), RasterImage.LoadCmyk32Pixels(Rectangle), RasterImage.LoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader), RasterImage.LoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader), RasterImage.SaveRawData(byte[], int, Rectangle, RawDataSettings), RasterImage.SaveArgb32Pixels(Rectangle, int[]), RasterImage.SavePixels(Rectangle, Color[]), RasterImage.SaveCmykPixels(Rectangle, CmykColor[]), RasterImage.SaveCmyk32Pixels(Rectangle, int[]), RasterImage.SetResolution(double, double), RasterImage.SetPalette(IColorPalette, bool), RasterImage.Resize(int, int, ImageResizeSettings), RasterImage.Rotate(float, bool, Color), RasterImage.Rotate(float), RasterImage.BinarizeFixed(byte), RasterImage.BinarizeOtsu(), RasterImage.BinarizeBradley(double), RasterImage.BinarizeBradley(double, int), RasterImage.Blend(Point, RasterImage, Rectangle, byte), RasterImage.Blend(Point, RasterImage, byte), RasterImage.Grayscale(), RasterImage.AdjustBrightness(int), RasterImage.AdjustContrast(float), RasterImage.AdjustGamma(float, float, float), RasterImage.AdjustGamma(float), RasterImage.GetSkewAngle(), RasterImage.NormalizeAngle(), RasterImage.NormalizeAngle(bool, Color), RasterImage.Filter(Rectangle, FilterOptionsBase), RasterImage.ReplaceColor(Color, byte, Color), RasterImage.ReplaceColor(int, byte, int), RasterImage.ReplaceNonTransparentColors(Color), RasterImage.ReplaceNonTransparentColors(int), RasterImage.ToBitmap(), RasterImage.PremultiplyComponents, RasterImage.UseRawData, RasterImage.UpdateXmpData, RasterImage.XmpData, RasterImage.RawIndexedColorConverter, RasterImage.RawCustomColorConverter, RasterImage.RawFallbackIndex, RasterImage.RawDataSettings, RasterImage.UsePalette, RasterImage.RawDataFormat, RasterImage.RawLineSize, RasterImage.IsRawDataAvailable, RasterImage.HorizontalResolution, RasterImage.VerticalResolution, RasterImage.HasTransparentColor, RasterImage.HasAlpha, RasterImage.TransparentColor, RasterImage.ImageOpacity, Image.CanLoad(string), Image.CanLoad(string, LoadOptions), Image.CanLoad(Stream), Image.CanLoad(Stream, LoadOptions), Image.Create(ImageOptionsBase, int, int), Image.Create(Image[]), Image.Create(MultipageCreateOptions), Image.Create(string[], bool), Image.Create(string[]), Image.Create(Image[], bool), Image.GetFileFormat(string), Image.GetFileFormat(Stream), Image.GetFittingRectangle(Rectangle, int, int), Image.GetFittingRectangle(Rectangle, int[], int, int), Image.Load(string, LoadOptions), Image.Load(string), Image.Load(Stream, LoadOptions), Image.Load(Stream), Image.GetProportionalWidth(int, int, int), Image.GetProportionalHeight(int, int, int), Image.RemoveMetadata(), Image.CanSave(ImageOptionsBase), Image.Resize(int, int), Image.Resize(int, int, ResizeType), Image.Resize(int, int, ImageResizeSettings), Image.GetDefaultOptions(object[]), Image.GetOriginalOptions(), Image.ResizeWidthProportionally(int), Image.ResizeHeightProportionally(int), Image.ResizeWidthProportionally(int, ResizeType), Image.ResizeHeightProportionally(int, ResizeType), Image.ResizeWidthProportionally(int, ImageResizeSettings), Image.ResizeHeightProportionally(int, ImageResizeSettings), Image.RotateFlip(RotateFlipType), Image.Rotate(float), Image.Crop(Rectangle), Image.Crop(int, int, int, int), Image.Save(), Image.Save(string), Image.Save(string, ImageOptionsBase), Image.Save(string, ImageOptionsBase, Rectangle), Image.Save(Stream, ImageOptionsBase), Image.Save(Stream, ImageOptionsBase, Rectangle), Image.GetSerializedStream(ImageOptionsBase, Rectangle, out int), Image.SetPalette(IColorPalette, bool), Image.BitsPerPixel, Image.Bounds, Image.Container, Image.Height, Image.Palette, Image.UsePalette, Image.Size, Image.Width, Image.InterruptMonitor, Image.BufferSizeHint, Image.AutoAdjustPalette, Image.HasBackgroundColor, Image.FileFormat, Image.BackgroundColor, DataStreamSupporter.CacheData(), DataStreamSupporter.Save(), DataStreamSupporter.Save(Stream), DataStreamSupporter.Save(string), DataStreamSupporter.Save(string, bool), DataStreamSupporter.DataStreamContainer, DataStreamSupporter.IsCached, DisposableObject.Dispose(), DisposableObject.Disposed, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

Change Color Type in DICOM compression.```csharp [C#]

                                              using (var inputImage = Image.Load("original.jpg"))
                                              {
                                                  var options = new DicomOptions { ColorType = ColorType.Grayscale8Bit };

                                                  inputImage.Save("original_8Bit.dcm", options);
                                              }

Use RLE compression in DICOM image.```csharp
[C#]

                                              using (var inputImage = Image.Load("original.jpg"))
                                              {
                                                  var options = new DicomOptions
                                                  {
                                                      ColorType = ColorType.Rgb24Bit,
                                                      Compression = new Compression { Type = CompressionType.Rle }
                                                  };

                                                  inputImage.Save("original_RLE.dcm", options);
                                              }

Use JPEG 2000 compression in DICOM image.```csharp [C#]

                                                using (var inputImage = Image.Load("original.jpg"))
                                                {
                                                    var options = new DicomOptions
                                                    {
                                                        ColorType = ColorType.Rgb24Bit,
                                                        Compression = new Compression
                                                        {
                                                            Type = CompressionType.Jpeg2000,
                                                            Jpeg2000 = new Jpeg2000Options
                                                            {
                                                                Codec = Jpeg2000Codec.Jp2,
                                                                Irreversible = false
                                                            }
                                                        }
                                                    };

                                                    inputImage.Save("original_JPEG2000.dcm", options);
                                                }

Use JPEG compression in DICOM image.```csharp
[C#]

                                               using (var inputImage = Image.Load("original.jpg"))
                                               {
                                                   var options = new DicomOptions
                                                   {
                                                       ColorType = ColorType.Rgb24Bit,
                                                       Compression = new Compression
                                                       {
                                                           Type = CompressionType.Jpeg,
                                                           Jpeg = new JpegOptions
                                                           {
                                                               CompressionType = JpegCompressionMode.Baseline,
                                                               SampleRoundingMode = SampleRoundingMode.Truncate,
                                                               Quality = 50
                                                           }
                                                       }
                                                   };

                                                   inputImage.Save("original_JPEG.dcm", options);
                                               }

This example shows how to load a DICOM image from a file stream.```csharp [C#]

                                                                       string dir = "c:\\temp\\";

                                                                       // Load a DICOM image from a file stream.
                                                                       using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.dicom"))
                                                                       {
                                                                           using (Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = new Aspose.Imaging.FileFormats.Dicom.DicomImage(stream))
                                                                           {
                                                                               // Save each page as an individual PNG image.                    
                                                                               foreach (Aspose.Imaging.FileFormats.Dicom.DicomPage dicomPage in dicomImage.DicomPages)
                                                                               {
                                                                                   // Generate a file name based on the page index.
                                                                                   string fileName = string.Format("sample.{0}.png", dicomPage.Index);

                                                                                   // A DICOM page is a raster image, so all allowed operations with a raster image are applicable to a DICOM page.
                                                                                   dicomPage.Save(dir + fileName, new Aspose.Imaging.ImageOptions.PngOptions());
                                                                               }
                                                                           }
                                                                       }

Create a multi-page Dicom image.```csharp
[C#]

                                           using (DicomImage image = (DicomImage)Image.Create(
                                                   new DicomOptions() { Source = new StreamSource(new MemoryStream()) },
                                                   100,
                                                   100))
                                           {
                                               // Draw something using vector graphics
                                               Graphics graphics = new Graphics(image);
                                               graphics.FillRectangle(new SolidBrush(Color.BlueViolet), image.Bounds);
                                               graphics.FillRectangle(new SolidBrush(Color.Aqua), 10, 20, 50, 20);
                                               graphics.FillEllipse(new SolidBrush(Color.Orange), 30, 50, 70, 30);

                                               // Save the pixels of the drawn image. They are now on the first page of the Dicom image.
                                               int[] pixels = image.LoadArgb32Pixels(image.Bounds);

                                               // Add a few pages after, making them darker
                                               for (int i = 1; i < 5; i++)
                                               {
                                                   DicomPage page = image.AddPage();
                                                   page.SaveArgb32Pixels(page.Bounds, pixels);
                                                   page.AdjustBrightness(i * 30);
                                               }

                                               // Add a few pages in front of the main page, making them brighter
                                               for (int i = 1; i < 5; i++)
                                               {
                                                   DicomPage page = image.InsertPage(0);
                                                   page.SaveArgb32Pixels(page.Bounds, pixels);
                                                   page.AdjustBrightness(-i * 30);
                                               }

                                               // Save the created multi-page image to the output file
                                               image.Save("MultiPage.dcm");
                                           }

Constructors

DicomImage(DicomOptions, int, int)

Initialize a fresh instance of the DicomImage class effortlessly with this constructor, utilizing dicomOptions parameters. Perfect for developers looking to dive into Aspose.Imaging.FileFormats.Dicom.DicomImage objects swiftly and efficiently in their projects.

public DicomImage(DicomOptions dicomOptions, int width, int height)

Parameters

dicomOptions DicomOptions

The dicom options.

width int

The width.

height int

The height.

DicomImage(Stream, LoadOptions)

Initiate a new instance of the DicomImage class smoothly by employing a stream and loadOptions parameters in this constructor. Ideal for developers eager to start working with Aspose.Imaging.FileFormats.Dicom.DicomImage objects promptly and effectively in their projects.

public DicomImage(Stream stream, LoadOptions loadOptions)

Parameters

stream Stream

The stream.

loadOptions LoadOptions

The load options.

Examples

This example shows how to load a DICOM image from a file stream to stay within the specified memory limit.```csharp [C#]

                                                                                                                 string dir = "c:\\temp\\";

                                                                                                                 // Load a DICOM image from a file stream.
                                                                                                                 using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "multiframe.dicom"))
                                                                                                                 {
                                                                                                                     // The max allowed size for all internal buffers is 256KB.
                                                                                                                     Aspose.Imaging.LoadOptions loadOptions = new Aspose.Imaging.LoadOptions();
                                                                                                                     loadOptions.BufferSizeHint = 256 * 1024;

                                                                                                                     using (Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = new Aspose.Imaging.FileFormats.Dicom.DicomImage(stream, loadOptions))
                                                                                                                     {
                                                                                                                         // Save each page as an individual PNG image.
                                                                                                                         foreach (Aspose.Imaging.FileFormats.Dicom.DicomPage dicomPage in dicomImage.DicomPages)
                                                                                                                         {
                                                                                                                             // Generate a file name based on the page index.
                                                                                                                             string fileName = string.Format("multiframe.{0}.png", dicomPage.Index);

                                                                                                                             // A DICOM page is a raster image, so all allowed operations with a raster image are applicable to a DICOM page.
                                                                                                                             dicomPage.Save(dir + fileName, new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage__ctor_System_IO_Stream_"></a> DicomImage\(Stream\)

Create a new instance of the DicomImage class by utilizing a stream parameter
in this constructor. Perfect for developers seeking a streamlined way to initialize
Aspose.Imaging.FileFormats.Dicom.DicomImage objects from existing data streams in their projects.

```csharp
public DicomImage(Stream stream)

Parameters

stream Stream

The stream.

Examples

This example shows how to load a DICOM image from a file stream.```csharp [C#]

                                                                       string dir = "c:\\temp\\";

                                                                       // Load a DICOM image from a file stream.
                                                                       using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "sample.dicom"))
                                                                       {
                                                                           using (Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = new Aspose.Imaging.FileFormats.Dicom.DicomImage(stream))
                                                                           {
                                                                               // Save each page as an individual PNG image.                    
                                                                               foreach (Aspose.Imaging.FileFormats.Dicom.DicomPage dicomPage in dicomImage.DicomPages)
                                                                               {
                                                                                   // Generate a file name based on the page index.
                                                                                   string fileName = string.Format("sample.{0}.png", dicomPage.Index);

                                                                                   // A DICOM page is a raster image, so all allowed operations with a raster image are applicable to a DICOM page.
                                                                                   dicomPage.Save(dir + fileName, new Aspose.Imaging.ImageOptions.PngOptions());
                                                                               }
                                                                           }
                                                                       }

## Properties

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_ActivePage"></a> ActivePage

Manage the active page of the image with this intuitive property. Ideal for developers
seeking to dynamically switch between pages within multi-page images, ensuring efficient
navigation and processing.

```csharp
public DicomPage ActivePage { get; set; }

Property Value

DicomPage

Exceptions

DicomImageException

The active page cannot be set as it belongs to another image.

ActivePageIndex

Retrieve the index of the active page effortlessly with this intuitive property. Ideal for developers seeking quick access to the current page index within multi-page images, ensuring efficient navigation and processing.

public int ActivePageIndex { get; }

Property Value

int

DicomPages

Access the pages of the image with this intuitive property. Ideal for developers seeking to interact with individual pages within the image, ensuring seamless navigation and manipulation.

public DicomPage[] DicomPages { get; }

Property Value

DicomPage[]

FileFormat

Retrieve the file format value effortlessly with this intuitive property. Ideal for developers seeking quick access to the format of the image file, ensuring efficient handling and processing based on the file type.

public override FileFormat FileFormat { get; }

Property Value

FileFormat

FileInfo

Retrieve valuable header information from the DICOM file effortlessly with this intuitive property. Ideal for developers seeking quick access to essential details encapsulated within the DICOM file, ensuring efficient data extraction and analysis.

public DicomImageInfo FileInfo { get; }

Property Value

DicomImageInfo

HasAlpha

Retrieve whether the image has an alpha channel effortlessly with this intuitive property. Ideal for developers seeking to determine if the image contains transparency information, ensuring precise handling of alpha channel data in image processing tasks.

public override bool HasAlpha { get; }

Property Value

bool

PageCount

Retrieve the total page count of the image with this intuitive property. Ideal for developers seeking quick access to the number of pages within an image, ensuring efficient navigation and management.

public override int PageCount { get; }

Property Value

int

Pages

Access the pages of the image with this intuitive property. Ideal for developers seeking to interact with individual pages within the image, ensuring seamless navigation and manipulation.

public override Image[] Pages { get; }

Property Value

Image[]

Methods

AddPage(RasterImage)

Expand your image collection by adding a new page with this intuitive method. Ideal for developers seeking to dynamically append pages to multi-page images, ensuring seamless expansion and organization of image content.

public void AddPage(RasterImage page)

Parameters

page RasterImage

The page to add.

Exceptions

ArgumentNullException

page is null.

AddPage()

Append a new page to the end of the image’s page list with this straightforward method. Ideal for developers seeking to dynamically expand multi-page images, ensuring seamless integration and organization of image content.

public DicomPage AddPage()

Returns

DicomPage

The newly created Aspose.Imaging.FileFormats.Dicom.DicomPage.

Examples

Create a multi-page Dicom image.```csharp [C#]

                                       using (DicomImage image = (DicomImage)Image.Create(
                                               new DicomOptions() { Source = new StreamSource(new MemoryStream()) },
                                               100,
                                               100))
                                       {
                                           // Draw something using vector graphics
                                           Graphics graphics = new Graphics(image);
                                           graphics.FillRectangle(new SolidBrush(Color.BlueViolet), image.Bounds);
                                           graphics.FillRectangle(new SolidBrush(Color.Aqua), 10, 20, 50, 20);
                                           graphics.FillEllipse(new SolidBrush(Color.Orange), 30, 50, 70, 30);

                                           // Save the pixels of the drawn image. They are now on the first page of the Dicom image.
                                           int[] pixels = image.LoadArgb32Pixels(image.Bounds);

                                           // Add a few pages after, making them darker
                                           for (int i = 1; i &lt; 5; i++)
                                           {
                                               DicomPage page = image.AddPage();
                                               page.SaveArgb32Pixels(page.Bounds, pixels);
                                               page.AdjustBrightness(i * 30);
                                           }

                                           // Add a few pages in front of the main page, making them brighter
                                           for (int i = 1; i &lt; 5; i++)
                                           {
                                               DicomPage page = image.InsertPage(0);
                                               page.SaveArgb32Pixels(page.Bounds, pixels);
                                               page.AdjustBrightness(-i * 30);
                                           }

                                           // Save the created multi-page image to the output file
                                           image.Save("MultiPage.dcm");
                                       }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_AdjustBrightness_System_Int32_"></a> AdjustBrightness\(int\)

Enhance image luminance with the adjustment of <code class="paramref">brightness</code>, a
parameterized method that allows developers to finely tune the luminosity of images.
This user-friendly function empowers developers to seamlessly manipulate image
brightness, offering flexibility and control over visual aesthetics.

```csharp
public override void AdjustBrightness(int brightness)

Parameters

brightness int

Brightness value.

Examples

The following example performs brightness correction of a DICOM image.```csharp [C#]

                                                                             string dir = "c:\\temp\\";

                                                                             using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                             {
                                                                                 Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                 // Set the brightness value. The accepted values of brightness are in the range [-255, 255].
                                                                                 dicomImage.AdjustBrightness(50);
                                                                                 dicomImage.Save(dir + "sample.AdjustBrightness.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                             }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_AdjustContrast_System_Single_"></a> AdjustContrast\(float\)

Enhance Aspose.Imaging.Image contrast with this user-friendly method,
which adjusts the disparity between light and dark areas. Improve visual clarity and
definition effortlessly, providing developers with intuitive control over
image contrast for optimal rendering.

```csharp
public override void AdjustContrast(float contrast)

Parameters

contrast float

Contrast value (in range [-100; 100])

Examples

The following example performs contrast correction of a DICOM image.```csharp [C#]

                                                                           string dir = "c:\\temp\\";

                                                                           using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                           {
                                                                               Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                               // Set the contrast value. The accepted values of contrast are in the range [-100f, 100f].
                                                                               dicomImage.AdjustContrast(50f);
                                                                               dicomImage.Save(dir + "sample.AdjustContrast.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                           }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_AdjustGamma_System_Single_"></a> AdjustGamma\(float\)

Enhance image quality and adjust it with gamma correction, a powerful technique
for fine-tuning visual appearance. Perfect for developers aiming to optimize image
presentation, adjust color balance, and ensure consistent rendering across different
devices and environments.

```csharp
public override void AdjustGamma(float gamma)

Parameters

gamma float

Gamma for red, green and blue channels coefficient

Examples

The following example performs gamma-correction of a DICOM image.```csharp [C#]

                                                                        string dir = "c:\\temp\\";

                                                                        using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                        {
                                                                            Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                            // Set gamma coefficient for red, green and blue channels.
                                                                            dicomImage.AdjustGamma(2.5f);
                                                                            dicomImage.Save(dir + "sample.AdjustGamma.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                        }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_AdjustGamma_System_Single_System_Single_System_Single_"></a> AdjustGamma\(float, float, float\)

Achieve precise color adjustments by applying gamma correction independently
to the red, green, and blue components of an image. This method ensures accurate
color balance and optimal visual output, catering to developers seeking granular
control over image rendering and color accuracy.

```csharp
public override void AdjustGamma(float gammaRed, float gammaGreen, float gammaBlue)

Parameters

gammaRed float

Gamma for red channel coefficient

gammaGreen float

Gamma for green channel coefficient

gammaBlue float

Gamma for blue channel coefficient

Examples

The following example performs gamma-correction of a DICOM image applying different coefficients for color components.```csharp [C#]

                                                                                                                             string dir = "c:\\temp\\";

                                                                                                                             using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                             {
                                                                                                                                 Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                                 // Set individual gamma coefficients for red, green and blue channels.
                                                                                                                                 dicomImage.AdjustGamma(1.5f, 2.5f, 3.5f);
                                                                                                                                 dicomImage.Save(dir + "sample.AdjustGamma.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                             }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_BinarizeBradley_System_Double_System_Int32_"></a> BinarizeBradley\(double, int\)

Binarize images with Bradley's adaptive thresholding algorithm, leveraging integral
image thresholding for improved performance. Ideal for developers looking to
automatically segment images based on local variations in brightness, ensuring
accurate object detection and extraction in varying lighting conditions.

```csharp
public override void BinarizeBradley(double brightnessDifference, int windowSize)

Parameters

brightnessDifference double

The brightness difference between pixel and the average of an s x s window of pixels centered around this pixel.

windowSize int

The size of s x s window of pixels centered around this pixel

Examples

The following example binarizes a DICOM image with Bradley’s adaptive thresholding algorithm with the specified window size. Binarized images contain only 2 colors - black and white.```csharp [C#]

                                                                                                                                                                                             string dir = "c:\\temp\\";

                                                                                                                                                                                             using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                                             {
                                                                                                                                                                                                 Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                                                                                                 // Binarize the image with a brightness difference of 5. The brightness is a difference between a pixel and the average of an 10 x 10 window of pixels centered around this pixel.
                                                                                                                                                                                                 dicomImage.BinarizeBradley(5, 10);
                                                                                                                                                                                                 dicomImage.Save(dir + "sample.BinarizeBradley5_10x10.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                                             }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_BinarizeFixed_System_Byte_"></a> BinarizeFixed\(byte\)

Easily convert the image into a binary format using a predefined threshold
with this straightforward method. Ideal for developers looking to simplify image
processing tasks by segmenting the image into foreground and background components
based on specified intensity levels.

```csharp
public override void BinarizeFixed(byte threshold)

Parameters

threshold byte

Threshold value. If corresponding gray value of a pixel is greater than threshold, a value of 255 will be assigned to it, 0 otherwise.

Examples

The following example binarizes a DICOM image with the predefined threshold. Binarized images contain only 2 colors - black and white.```csharp [C#]

                                                                                                                                             string dir = "c:\\temp\\";

                                                                                                                                             using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                             {
                                                                                                                                                 Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                                                 // Binarize the image with a threshold value of 127.
                                                                                                                                                 // If a corresponding gray value of a pixel is greater than 127, a value of 255 will be assigned to it, 0 otherwise.
                                                                                                                                                 dicomImage.BinarizeFixed(127);
                                                                                                                                                 dicomImage.Save(dir + "sample.BinarizeFixed.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                             }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_BinarizeOtsu"></a> BinarizeOtsu\(\)

Apply Otsu thresholding to binarize the image, automatically determining the optimal
threshold value based on the image's histogram. Perfect for developers seeking
a reliable method to segment images into foreground and background regions with
minimal manual intervention.

```csharp
public override void BinarizeOtsu()

Examples

The following example binarizes a DICOM image with Otsu thresholding. Binarized images contain only 2 colors - black and white.```csharp [C#]

                                                                                                                                      string dir = "c:\\temp\\";

                                                                                                                                      using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                      {
                                                                                                                                          Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                                          // Binarize the image with Otsu thresholding.
                                                                                                                                          dicomImage.BinarizeOtsu();
                                                                                                                                          dicomImage.Save(dir + "sample.BinarizeOtsu.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                      }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_CacheData"></a> CacheData\(\)

This method efficiently caches data, optimizing performance and ensuring swift access
when needed. Ideal for developers seeking to enhance the speed and efficiency of their
applications by intelligently managing data resources.

```csharp
public override void CacheData()

Examples

The following example shows how to cache all pages of a DICOM image.```csharp [C#]

                                                                           string dir = "c:\\temp\\";

                                                                           // Load an image from a DICOM file.
                                                                           using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                           {
                                                                               // This call caches all the pages so that no additional data loading will be performed from the underlying data stream.
                                                                               image.CacheData();

                                                                               // Or you can cache the pages individually.
                                                                               foreach (Aspose.Imaging.FileFormats.Dicom.DicomPage page in image.DicomPages)
                                                                               {
                                                                                   page.CacheData();
                                                                               }
                                                                           }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_Crop_Aspose_Imaging_Rectangle_"></a> Crop\(Rectangle\)

Crop the image to remove unwanted areas and focus on essential content with this
simple method. Ideal for developers seeking to customize the visual composition of
images, ensuring they convey the desired message effectively.

```csharp
public override void Crop(Rectangle rectangle)

Parameters

rectangle Rectangle

The rectangle.

Examples

The following example crops a DICOM image. The cropping area is be specified via Aspose.Imaging.Rectangle.```csharp [C#]

                                                                                                                 string dir = "c:\\temp\\";

                                                                                                                 using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                 {
                                                                                                                     Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                     // Crop the image. The cropping area is the rectangular central area of the image.
                                                                                                                     Aspose.Imaging.Rectangle area = new Aspose.Imaging.Rectangle(dicomImage.Width / 4, dicomImage.Height / 4, dicomImage.Width / 2, dicomImage.Height / 2);
                                                                                                                     dicomImage.Crop(area);

                                                                                                                     // Save the cropped image to PNG
                                                                                                                     dicomImage.Save(dir + "sample.Crop.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                 }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_Crop_System_Int32_System_Int32_System_Int32_System_Int32_"></a> Crop\(int, int, int, int\)

Adjust the cropping area of the image by applying shifts with this versatile method.
Perfect for developers who need precise control over the cropping process, ensuring
that important details are retained while eliminating unnecessary elements.

```csharp
public override void Crop(int leftShift, int rightShift, int topShift, int bottomShift)

Parameters

leftShift int

The left shift.

rightShift int

The right shift.

topShift int

The top shift.

bottomShift int

The bottom shift.

Examples

The following example crops a DICOM image. The cropping area is specified via Left, Top, Right, Bottom margins.```csharp [C#]

                                                                                                                      string dir = @"c:\temp\";

                                                                                                                      using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                      {
                                                                                                                          Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                          // Crop again. Set a margin of 10% of the image size.
                                                                                                                          int horizontalMargin = dicomImage.Width / 10;
                                                                                                                          int verticalMargin = dicomImage.Height / 10;
                                                                                                                          dicomImage.Crop(horizontalMargin, horizontalMargin, verticalMargin, verticalMargin);

                                                                                                                          // Save the cropped image to PNG.
                                                                                                                          dicomImage.Save(dir + "sample.Crop.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                      }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_Dither_Aspose_Imaging_DitheringMethod_System_Int32_Aspose_Imaging_IColorPalette_"></a> Dither\(DitheringMethod, int, IColorPalette\)

Enhance the current image by applying dithering effects with this straightforward
method. Perfect for developers aiming to add texture and depth to images,
improving their visual quality and overall appeal.

```csharp
public override void Dither(DitheringMethod ditheringMethod, int bitsCount, IColorPalette customPalette)

Parameters

ditheringMethod DitheringMethod

The dithering method.

bitsCount int

The final bits count for dithering.

customPalette IColorPalette

The custom palette for dithering.

Examples

The following example loads a DICOM image and performs threshold and floyd dithering using different palette depth.```csharp [C#]

                                                                                                                          string dir = "c:\\temp\\";

                                                                                                                          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                          {
                                                                                                                              Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                              // Perform threshold dithering using 4-bit color palette which contains 16 colors.
                                                                                                                              // The more bits specified the higher quality and the bigger size of the output image.
                                                                                                                              // Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
                                                                                                                              dicomImage.Dither(Aspose.Imaging.DitheringMethod.ThresholdDithering, 4, null);

                                                                                                                              dicomImage.Save(dir + "sample.ThresholdDithering4.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                          }

                                                                                                                          using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                          {
                                                                                                                              Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                              // Perform floyd dithering using 1-bit color palette which contains only 2 colors - black and white.
                                                                                                                              // The more bits specified the higher quality and the bigger size of the output image.
                                                                                                                              // Note that only 1-bit, 4-bit and 8-bit palettes are supported at the moment.
                                                                                                                              dicomImage.Dither(Aspose.Imaging.DitheringMethod.FloydSteinbergDithering, 1, null);

                                                                                                                              dicomImage.Save(dir + "sample.FloydSteinbergDithering1.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                          }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_Filter_Aspose_Imaging_Rectangle_Aspose_Imaging_ImageFilters_FilterOptions_FilterOptionsBase_"></a> Filter\(Rectangle, FilterOptionsBase\)

Effortlessly enhance specific areas of your image by applying filters to designated
rectangles. This method provides developers with precise control over
image manipulation, allowing for targeted adjustments to achieve desired
visual effects with ease.

```csharp
public override void Filter(Rectangle rectangle, FilterOptionsBase options)

Parameters

rectangle Rectangle

The rectangle.

options FilterOptionsBase

The options.

Examples

The following example applies various types of filters to a DICOM image.```csharp [C#]

                                                                               string dir = "c:\\temp\\";

                                                                               using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                               {
                                                                                   Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                   // Apply a median filter with a rectangle size of 5 to the entire image.
                                                                                   dicomImage.Filter(dicomImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.MedianFilterOptions(5));
                                                                                   dicomImage.Save(dir + "sample.MedianFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                               }

                                                                               using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                               {
                                                                                   Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                   // Apply a bilateral smoothing filter with a kernel size of 5 to the entire image.
                                                                                   dicomImage.Filter(dicomImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.BilateralSmoothingFilterOptions(5));
                                                                                   dicomImage.Save(dir + "sample.BilateralSmoothingFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                               }

                                                                               using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                               {
                                                                                   Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                   // Apply a Gaussian blur filter with a radius of 5 and a sigma value of 4.0 to the entire image.
                                                                                   dicomImage.Filter(dicomImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussianBlurFilterOptions(5, 4.0));
                                                                                   dicomImage.Save(dir + "sample.GaussianBlurFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                               }

                                                                               using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                               {
                                                                                   Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                   // Apply a Gauss-Wiener filter with a radius of 5 and a smooth value of 4.0 to the entire image.
                                                                                   dicomImage.Filter(dicomImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussWienerFilterOptions(5, 4.0));
                                                                                   dicomImage.Save(dir + "sample.GaussWienerFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                               }

                                                                               using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                               {
                                                                                   Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                   // Apply a motion wiener filter with a length of 5, a smooth value of 4.0 and an angle of 90.0 degrees to the entire image.
                                                                                   dicomImage.Filter(dicomImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.MotionWienerFilterOptions(10, 1.0, 90.0));
                                                                                   dicomImage.Save(dir + "sample.MotionWienerFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                               }

                                                                               using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                               {
                                                                                   Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                   // Apply a sharpen filter with a kernel size of 5 and a sigma value of 4.0 to the entire image.
                                                                                   dicomImage.Filter(dicomImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.SharpenFilterOptions(5, 4.0));
                                                                                   dicomImage.Save(dir + "sample.SharpenFilter.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                               }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_Grayscale"></a> Grayscale\(\)

Easily transform images into their grayscale representation, simplifying visual
analysis and processing tasks. Perfect for developers seeking to enhance image clarity,
reduce complexity, and facilitate efficient grayscale-based algorithms
for diverse applications.

```csharp
public override void Grayscale()

Examples

The following example transforms a colored DICOM image to its grayscale representation. Grayscale images are composed exclusively of shades of gray and carry only intensity information.```csharp [C#]

                                                                                                                                                                                                string dir = "c:\\temp\\";

                                                                                                                                                                                                using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                                                {
                                                                                                                                                                                                    Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                                                                                                                                    dicomImage.Grayscale();
                                                                                                                                                                                                    dicomImage.Save(dir + "sample.Grayscale.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                                                }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_InsertPage_System_Int32_"></a> InsertPage\(int\)

Insert a new page into the image's page list at a specified index with this intuitive
method. Ideal for developers seeking precise control over the arrangement of pages in
multi-page images, ensuring seamless organization and customization of image content.

```csharp
public DicomPage InsertPage(int pageIndex)

Parameters

pageIndex int

Index of the page.

Returns

DicomPage

The newly created Aspose.Imaging.FileFormats.Dicom.DicomPage.

Examples

Create a multi-page Dicom image.```csharp [C#]

                                       using (DicomImage image = (DicomImage)Image.Create(
                                               new DicomOptions() { Source = new StreamSource(new MemoryStream()) },
                                               100,
                                               100))
                                       {
                                           // Draw something using vector graphics
                                           Graphics graphics = new Graphics(image);
                                           graphics.FillRectangle(new SolidBrush(Color.BlueViolet), image.Bounds);
                                           graphics.FillRectangle(new SolidBrush(Color.Aqua), 10, 20, 50, 20);
                                           graphics.FillEllipse(new SolidBrush(Color.Orange), 30, 50, 70, 30);

                                           // Save the pixels of the drawn image. They are now on the first page of the Dicom image.
                                           int[] pixels = image.LoadArgb32Pixels(image.Bounds);

                                           // Add a few pages after, making them darker
                                           for (int i = 1; i &lt; 5; i++)
                                           {
                                               DicomPage page = image.AddPage();
                                               page.SaveArgb32Pixels(page.Bounds, pixels);
                                               page.AdjustBrightness(i * 30);
                                           }

                                           // Add a few pages in front of the main page, making them brighter
                                           for (int i = 1; i &lt; 5; i++)
                                           {
                                               DicomPage page = image.InsertPage(0);
                                               page.SaveArgb32Pixels(page.Bounds, pixels);
                                               page.AdjustBrightness(-i * 30);
                                           }

                                           // Save the created multi-page image to the output file
                                           image.Save("MultiPage.dcm");
                                       }

#### Exceptions

 [ArgumentOutOfRangeException](https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception)

<code class="paramref">pageIndex</code> is out of range.

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_ReleaseManagedResources"></a> ReleaseManagedResources\(\)

Releases the managed resources. Make sure no unmanaged resources are released here, since they may have been
already released.

```csharp
protected override void ReleaseManagedResources()

RemovePage(int)

Eliminate the page at the specified index from the page list with this convenient method. Ideal for developers seeking precise control over the management of multi-page images, ensuring seamless organization and customization of image content.

public void RemovePage(int pageIndex)

Parameters

pageIndex int

Index of the page.

Exceptions

ArgumentOutOfRangeException

pageIndex is out of range.

Resize(int, int, ResizeType)

Adjust the size of the image with this straightforward method. Ideal for developers looking to dynamically resize images, ensuring they fit seamlessly into various contexts and layouts within their applications.

public override void Resize(int newWidth, int newHeight, ResizeType resizeType)

Parameters

newWidth int

The new width.

newHeight int

The new height.

resizeType ResizeType

The resize type.

Examples

This example loads a DICOM image and resizes it using various resizing methods.```csharp [C#]

                                                                                      string dir = "c:\\temp\\";

                                                                                      using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                      {
                                                                                          // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                          image.Resize(image.Width* 2, image.Height* 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                          // Save to PNG with default options.
                                                                                          image.Save(dir + "upsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                      }

                                                                                      using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                      {
                                                                                          // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                          image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                          // Save to PNG with default options.
                                                                                          image.Save(dir + "downsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                      }

                                                                                      using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                      {
                                                                                          // Scale up by 2 times using Bilinear resampling.
                                                                                          image.Resize(image.Width* 2, image.Height* 2, Aspose.Imaging.ResizeType.BilinearResample);

                                                                                          // Save to PNG with default options.
                                                                                          image.Save(dir + "upsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                      }

                                                                                      using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                      {
                                                                                          // Scale down by 2 times using Bilinear resampling.
                                                                                          image.Resize(image.Width / 2, image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);

                                                                                          // Save to PNG with default options.
                                                                                          image.Save(dir + "downsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                      }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_Resize_System_Int32_System_Int32_Aspose_Imaging_ImageResizeSettings_"></a> Resize\(int, int, ImageResizeSettings\)

Adjust the size of your image with this simple resizing method. Whether you need to
shrink or enlarge your image, this function ensures that your resizing needs are met
efficiently and accurately, making it perfect for developers seeking quick and easy
image size adjustments.

```csharp
public override void Resize(int newWidth, int newHeight, ImageResizeSettings settings)

Parameters

newWidth int

The new width.

newHeight int

The new height.

settings ImageResizeSettings

The resize settings.

Examples

This example loads a DICOM image and resizes it using various resizing settings.```csharp [C#]

                                                                                       string dir = "c:\\temp\\";

                                                                                       Aspose.Imaging.ImageResizeSettings resizeSettings = new Aspose.Imaging.ImageResizeSettings();

                                                                                       // The adaptive algorithm based on weighted and blended rational function and lanczos3 interpolation.
                                                                                       resizeSettings.Mode = Aspose.Imaging.ResizeType.AdaptiveResample;

                                                                                       // The small rectangular filter
                                                                                       resizeSettings.FilterType = Aspose.Imaging.ImageFilterType.SmallRectangular;

                                                                                       // The number of colors in the palette.
                                                                                       resizeSettings.EntriesCount = 256;

                                                                                       // The color quantization is not used
                                                                                       resizeSettings.ColorQuantizationMethod = ColorQuantizationMethod.None;

                                                                                       // The euclidian method
                                                                                       resizeSettings.ColorCompareMethod = ColorCompareMethod.Euclidian;

                                                                                       using (Aspose.Imaging.Image image = (Aspose.Imaging.Image)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                       {
                                                                                           Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = (Aspose.Imaging.FileFormats.Dicom.DicomImage)image;

                                                                                           // Scale down by 2 times using adaptive resampling.
                                                                                           dicomImage.Resize(image.Width / 2, image.Height / 2, resizeSettings);

                                                                                           // Save to PNG
                                                                                           dicomImage.Save(dir + "downsample.adaptive.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                       }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_ResizeHeightProportionally_System_Int32_Aspose_Imaging_ResizeType_"></a> ResizeHeightProportionally\(int, ResizeType\)

Adjust the height of the image while maintaining its aspect ratio with this
user-friendly method. Perfect for developers seeking to dynamically resize images
while preserving their proportions, ensuring optimal display and usability
in their applications.

```csharp
public override void ResizeHeightProportionally(int newHeight, ResizeType resizeType)

Parameters

newHeight int

The new height.

resizeType ResizeType

Type of the resize.

Examples

This example loads a DICOM image and resizes it proportionally using various resizing methods. Only the height is specified, the width is calculated automatically.```csharp [C#]

                                                                                                                                                                          string dir = "c:\\temp\\";

                                                                                                                                                                          using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                          {
                                                                                                                                                                              // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                                                                                                              image.ResizeHeightProportionally(image.Height* 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                                                                                                              // Save to PNG with the default options.
                                                                                                                                                                              image.Save(dir + "upsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                          }

                                                                                                                                                                          using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                          {
                                                                                                                                                                              // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                                                                                                              image.ResizeHeightProportionally(image.Height / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                                                                                                              // Save to PNG with the default options.
                                                                                                                                                                              image.Save(dir + "downsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                          }

                                                                                                                                                                          using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                          {
                                                                                                                                                                              // Scale up by 2 times using Bilinear resampling.
                                                                                                                                                                              image.ResizeHeightProportionally(image.Height* 2, Aspose.Imaging.ResizeType.BilinearResample);

                                                                                                                                                                              // Save to PNG with the default options.
                                                                                                                                                                              image.Save(dir + "upsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                          }

                                                                                                                                                                          using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                          {
                                                                                                                                                                              // Scale down by 2 times using Bilinear resampling.
                                                                                                                                                                              image.ResizeHeightProportionally(image.Height / 2, Aspose.Imaging.ResizeType.BilinearResample);

                                                                                                                                                                              // Save to PNG with the default options.
                                                                                                                                                                              image.Save(dir + "downsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                          }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_ResizeProportional_System_Int32_System_Int32_Aspose_Imaging_ResizeType_"></a> ResizeProportional\(int, int, ResizeType\)

Resize the image while maintaining its aspect ratio with this convenient method. Ideal
for developers seeking to adjust the image dimensions proportionally, ensuring
consistency and preserving the original content's proportions.
The proportional resize will resize each frame according to the ratio of <code class="paramref">newWidth</code>/width and <code class="paramref">newHeight</code>/height.

```csharp
public void ResizeProportional(int newWidth, int newHeight, ResizeType resizeType)

Parameters

newWidth int

The new width.

newHeight int

The new height.

resizeType ResizeType

The resize type.

ResizeWidthProportionally(int, ResizeType)

Adjust the width of the image while maintaining its aspect ratio with this convenient method. Ideal for developers seeking to resize images proportionally, ensuring consistent and visually appealing results across different display environment.

public override void ResizeWidthProportionally(int newWidth, ResizeType resizeType)

Parameters

newWidth int

The new width.

resizeType ResizeType

Type of the resize.

Examples

This example loads a DICOM image and resizes it proportionally using various resizing methods. Only the width is specified, the height is calculated automatically.```csharp [C#]

                                                                                                                                                                          string dir = "c:\\temp\\";

                                                                                                                                                                          using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                          {
                                                                                                                                                                              // Scale up by 2 times using Nearest Neighbour resampling.
                                                                                                                                                                              image.ResizeWidthProportionally(image.Width* 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                                                                                                              // Save to PNG with the default options.
                                                                                                                                                                              image.Save(dir + "upsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                          }

                                                                                                                                                                          using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                          {
                                                                                                                                                                              // Scale down by 2 times using Nearest Neighbour resampling.
                                                                                                                                                                              image.ResizeWidthProportionally(image.Width / 2, Aspose.Imaging.ResizeType.NearestNeighbourResample);

                                                                                                                                                                              // Save to PNG with the default options.
                                                                                                                                                                              image.Save(dir + "downsample.nearestneighbour.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                          }

                                                                                                                                                                          using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                          {
                                                                                                                                                                              // Scale up by 2 times using Bilinear resampling.
                                                                                                                                                                              image.ResizeWidthProportionally(image.Width* 2, Aspose.Imaging.ResizeType.BilinearResample);

                                                                                                                                                                              // Save to PNG with the default options.
                                                                                                                                                                              image.Save(dir + "upsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                          }

                                                                                                                                                                          using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                                                          {
                                                                                                                                                                              // Scale down by 2 times using Bilinear resampling.
                                                                                                                                                                              image.ResizeWidthProportionally(image.Width / 2, Aspose.Imaging.ResizeType.BilinearResample);                

                                                                                                                                                                              // Save to PNG with the default options.
                                                                                                                                                                              image.Save(dir + "downsample.bilinear.png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                                                          }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_Rotate_System_Single_System_Boolean_Aspose_Imaging_Color_"></a> Rotate\(float, bool, Color\)

Rotate the image around its center with this convenient method. Ideal for developers
seeking to adjust image orientation dynamically, ensuring optimal presentation and
alignment within their applications.

```csharp
public override void Rotate(float angle, bool resizeProportionally, Color backgroundColor)

Parameters

angle float

The rotate angle in degrees. Positive values will rotate clockwise.

resizeProportionally bool

if set to true you will have your image size changed according to rotated rectangle (corner points) projections in other case that leaves dimensions untouched and only internal image contents are rotated.

backgroundColor Color

Color of the background.

Examples

This example shows how to rotate all pages of a DICOM image and save them all to a multi-frame TIFF image.```csharp [C#]

                                                                                                                 string dir = "c:\\temp\\";

                                                                                                                 // Load a DICOM image from a file stream.
                                                                                                                 using (System.IO.Stream stream = System.IO.File.OpenRead(dir + "multiframe.dicom"))
                                                                                                                 {
                                                                                                                     using (Aspose.Imaging.FileFormats.Dicom.DicomImage dicomImage = new Aspose.Imaging.FileFormats.Dicom.DicomImage(stream))
                                                                                                                     {
                                                                                                                         // Rotate the image around the center by 60 degrees clockwise.
                                                                                                                         // Use gray as the background color.
                                                                                                                         dicomImage.Rotate(60, true, Aspose.Imaging.Color.Gray);

                                                                                                                         Aspose.Imaging.ImageOptions.TiffOptions createOptions = new Aspose.Imaging.ImageOptions.TiffOptions(Imaging.FileFormats.Tiff.Enums.TiffExpectedFormat.Default);
                                                                                                                         createOptions.Compression = Aspose.Imaging.FileFormats.Tiff.Enums.TiffCompressions.Deflate;

                                                                                                                         // Note that if the image is colorful, it will be automatically converted to the grayscale format according to the options below
                                                                                                                         createOptions.Photometric = Aspose.Imaging.FileFormats.Tiff.Enums.TiffPhotometrics.MinIsBlack;
                                                                                                                         createOptions.BitsPerSample = new ushort[] { 8 };

                                                                                                                         // Create an array of TIFF frames.
                                                                                                                         // The number of the frames is equal to the number of the DJVU pages.
                                                                                                                         Aspose.Imaging.FileFormats.Tiff.TiffFrame[] tiffFrames = new Aspose.Imaging.FileFormats.Tiff.TiffFrame[dicomImage.DicomPages.Length];

                                                                                                                         // Save each page as an individual TIFF frame.
                                                                                                                         foreach (Aspose.Imaging.FileFormats.Dicom.DicomPage dicomPage in dicomImage.DicomPages)
                                                                                                                         {
                                                                                                                             // Create a TIFF frame based on the DICOM page.
                                                                                                                             tiffFrames[dicomPage.Index] = new Aspose.Imaging.FileFormats.Tiff.TiffFrame(dicomPage, createOptions);
                                                                                                                         }

                                                                                                                         // Compose a TIFF image from the frames.
                                                                                                                         using (Aspose.Imaging.FileFormats.Tiff.TiffImage tiffImage = new Aspose.Imaging.FileFormats.Tiff.TiffImage(tiffFrames))
                                                                                                                         {
                                                                                                                             // Save to a file.
                                                                                                                             tiffImage.Save(dir + "multiframe.tif");
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_RotateFlip_Aspose_Imaging_RotateFlipType_"></a> RotateFlip\(RotateFlipType\)

Easily manipulate the active frame by rotating, flipping, or performing both actions
simultaneously with this straightforward method. Ideal for developers who need to
dynamically adjust the orientation of specific frames within their image sequences,
ensuring optimal presentation and alignment.

```csharp
public override void RotateFlip(RotateFlipType rotateFlipType)

Parameters

rotateFlipType RotateFlipType

The rotate flip type.

Examples

This example loads a DICOM image, rotates it by 90 degrees clockwise and optionally flips the image horizontally and(or) vertically.```csharp [C#]

                                                                                                                                           string dir = "c:\\temp\\";

                                                                                                                                           Aspose.Imaging.RotateFlipType[] rotateFlipTypes = new Aspose.Imaging.RotateFlipType[]
                                                                                                                                           {
                                                                                                                                               Aspose.Imaging.RotateFlipType.Rotate90FlipNone,
                                                                                                                                               Aspose.Imaging.RotateFlipType.Rotate90FlipX,
                                                                                                                                               Aspose.Imaging.RotateFlipType.Rotate90FlipXY,
                                                                                                                                               Aspose.Imaging.RotateFlipType.Rotate90FlipY,
                                                                                                                                           };

                                                                                                                                           foreach (Aspose.Imaging.RotateFlipType rotateFlipType in rotateFlipTypes)
                                                                                                                                           {
                                                                                                                                               // Rotate, flip and save to the output file.
                                                                                                                                               using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                                                               {
                                                                                                                                                   image.RotateFlip(rotateFlipType);
                                                                                                                                                   image.Save(dir + "sample." + rotateFlipType + ".png", new Aspose.Imaging.ImageOptions.PngOptions());
                                                                                                                                               }
                                                                                                                                           }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_Save_System_IO_Stream_Aspose_Imaging_ImageOptionsBase_Aspose_Imaging_Rectangle_"></a> Save\(Stream, ImageOptionsBase, Rectangle\)

Easily save your image data to a specified stream in the desired file format
using this convenient method. Whether you're working with JPEG, PNG, or another format,
this function ensures that your image data is saved efficiently and accurately,
making it ideal for developers looking to streamline their file-saving processes.

```csharp
public override void Save(Stream stream, ImageOptionsBase optionsBase, Rectangle boundsRectangle)

Parameters

stream Stream

The stream to save the image’s data to.

optionsBase ImageOptionsBase

The save options.

boundsRectangle Rectangle

The destination image bounds rectangle. Set the empty rectangle for use sourse bounds.

Examples

The following example loads a DICOM image from a file, then saves the image to a PNG file stream.```csharp [C#]

                                                                                                        string dir = "c:\\temp\\";

                                                                                                        using (Aspose.Imaging.FileFormats.Dicom.DicomImage image = (Aspose.Imaging.FileFormats.Dicom.DicomImage)Aspose.Imaging.Image.Load(dir + "sample.dicom"))
                                                                                                        {
                                                                                                            Aspose.Imaging.ImageOptions.PngOptions saveOptions = new Aspose.Imaging.ImageOptions.PngOptions();
                                                                                                            Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(0, 0, image.Width / 2, image.Height / 2);
                                                                                                            using (System.IO.Stream outputStream = System.IO.File.Open(dir + "output.png", System.IO.FileMode.Create))
                                                                                                            {
                                                                                                                // Save the upper-left quarter of the image to a file stream.
                                                                                                                image.Save(outputStream, saveOptions, bounds);
                                                                                                            }
                                                                                                        }

### <a id="Aspose_Imaging_FileFormats_Dicom_DicomImage_SaveAll_System_String_Aspose_Imaging_ImageOptionsBase_"></a> SaveAll\(string, ImageOptionsBase\)

Preserve the object's data by saving it to the designated file (indexer + filename)
location along with specified file format and options. Ideal for developers seeking to
securely store data in various formats while maintaining flexibility and control over
saving parameters.

```csharp
public void SaveAll(string filePath, ImageOptionsBase options)

Parameters

filePath string

The file path.

options ImageOptionsBase

The options.

SaveData(Stream)

Saves the data.

protected override void SaveData(Stream stream)

Parameters

stream Stream

The stream to save data to.

SetResolution(double, double)

Adjust the resolution of this Aspose.Imaging.RasterImage with precision using this straightforward method. Ideal for developers looking to tailor image resolution to specific requirements, ensuring optimal display quality and file size management.

public override void SetResolution(double dpiX, double dpiY)

Parameters

dpiX double

The horizontal resolution, in dots per inch, of the Aspose.Imaging.RasterImage.

dpiY double

The vertical resolution, in dots per inch, of the Aspose.Imaging.RasterImage.

UpdateDimensions(int, int)

Updates the image dimensions.

protected override void UpdateDimensions(int newWidth, int newHeight)

Parameters

newWidth int

The new image width.

newHeight int

The new image height.