agentleFS
aspose-imagingaspose-imaging/agentic-net-examples/convert-dicom-images/agents.md

agentic-net-examples / convert-dicom-images

AGENTS.md1 starsChanged 7 months agoMITView on GitHub

C# examples for Convert DICOM Images using Aspose.Imaging for .NET

The file

We split this agents.md into the rules it gives an agent

7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When you need to turn a grayscale DICOM scan into a PNG with a specific colour map, you can apply a custom palette during the conversion …

    line 118
  2. Distinctive:

    If you have a folder full of DICOM files and must output PNGs that keep the original filenames, a simple batch‑convert loop lets you …

    line 119
  3. Very specific:

    When a DICOM image arrives as a byte array (for example from a web API), you can convert it to PNG entirely in memory by loading the bytes …

    line 121
  4. Distinctive:

    If you’re also working with other medical image formats, the Conversion category shows how to move between generic raster types, which can …

    line 125
  5. Distinctive:

    When your workflow involves converting the resulting PNGs to other raster formats (e.g., JPEG or TIFF), the Convert Raster Image category …

    line 127
  6. Very specific:

    Use PngOptions to set the Palette property with a custom ColorPalette before calling image.Save(outputPath, pngOptions).

    line 154
  7. Very specific:

    Create a PngOptions instance and set its CompressionLevel (0‑9) before saving the image, e.g., pngOptions.CompressionLevel = 6;.

    line 160

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
agents.md

AGENTS - Convert DICOM Images

Persona

You are a C# developer specializing in image processing using Aspose.Imaging for .NET, working within the Convert DICOM Images category. This folder contains standalone C# examples for Convert DICOM Images operations. See the root agents.md for repository-wide conventions and boundaries.

Required Namespaces

  • using Aspose.Imaging; (31/30 files) ← category-specific
  • using System; (30/30 files)
  • using System.IO; (30/30 files)
  • using Aspose.Imaging.ImageOptions; (30/30 files) ← category-specific
  • using Aspose.Imaging.FileFormats.Dicom; (22/30 files) ← category-specific
  • using Aspose.Imaging.FileFormats.Png; (7/30 files) ← category-specific
  • using Aspose.Imaging.CoreExceptions.ImageFormats; (2/30 files) ← category-specific
  • using Aspose.Imaging.ImageFilters.FilterOptions; (1/30 files) ← category-specific
  • using Aspose.Imaging.ProgressManagement; (1/30 files) ← category-specific
  • using Aspose.Imaging.CoreExceptions; (1/30 files) ← category-specific
  • using System.Threading.Tasks; (1/30 files)
  • using Aspose.Imaging.FileFormats.Tiff.Enums; (1/30 files) ← category-specific

Files in this folder

FileKey APIsDescription
load-a-dicom-file-from-disk-and-save-it-as-a-png-using-a-single-api-call.csDicomImage, PngOptionsLoad a DICOM file from disk and save it as a PNG using a single API call.
convert-a-dicom-image-stored-in-a-byte-array-to-png-by-using-memorystream-for-in-memory-processing.csDicomImage, LoadOptions, PngOptionsConvert a DICOM image stored in a byte array to PNG by using MemoryStream for in...
use-the-image-isvalid-property-to-verify-dicom-file-integrity-before-attempting-png-conversion.csDicomImage, PngOptionsUse the Image.IsValid property to verify DICOM file integrity before attempting ...
apply-a-median-filter-to-a-dicom-image-before-converting-it-to-png-to-reduce-noise.csDicomImage, MedianFilterOptions, PngOptionsApply a median filter to a DICOM image before converting it to PNG to reduce noi...
resize-a-dicom-image-to-specific-dimensions-prior-to-png-conversion-using-the-image-resize-method.csDicomImage, PngOptionsResize a DICOM image to specific dimensions prior to PNG conversion using the Im...
rotate-a-dicom-image-90-degrees-clockwise-before-saving-it-as-a-png-file.csPngOptionsRotate a DICOM image 90 degrees clockwise before saving it as a PNG file.
set-the-png-color-type-to-truecolor-during-conversion-to-preserve-full-color-information-from-dicom.csPngOptionsSet the PNG color type to truecolor during conversion to preserve full color inf...
configure-png-compression-level-in-pngoptions-to-balance-file-size-and-image-quality-during-conversion.csPngOptionsConfigure PNG compression level in PngOptions to balance file size and image qua...
iterate-through-each-frame-of-a-multi-page-dicom-and-export-every-frame-as-an-individual-png-file.csDicomImage, PngOptionsIterate through each frame of a multi‑page DICOM and export every frame as an in...
batch-convert-all-dicom-files-in-a-directory-to-png-format-while-preserving-original-filenames.csDicomImage, PngOptionsBatch convert all DICOM files in a directory to PNG format while preserving orig...
implement-progress-reporting-for-batch-conversion-of-dicom-files-to-png-using-iprogress-interface.csDicomImage, LoadOptions, PngOptionsImplement progress reporting for batch conversion of DICOM files to PNG using IP...
implement-a-retry-mechanism-that-attempts-dicom-to-png-conversion-up-to-three-times-on-transient-errors.csPngOptionsImplement a retry mechanism that attempts DICOM to PNG conversion up to three ti...
implement-exception-handling-to-gracefully-skip-corrupted-dicom-files-during-batch-png-conversion.csDicomImage, PngOptionsImplement exception handling to gracefully skip corrupted DICOM files during bat...
capture-and-log-aspose-imaging-exceptions-when-a-dicom-to-png-conversion-fails-due-to-corrupted-data.csPngOptionsCapture and log Aspose.Imaging exceptions when a DICOM to PNG conversion fails d...
use-a-using-statement-to-ensure-the-image-object-is-disposed-after-converting-dicom-to-png.csPngOptionsUse a using statement to ensure the Image object is disposed after converting DI...
save-the-resulting-png-image-to-a-memorystream-for-further-transmission-over-a-network.csPngOptionsSave the resulting PNG image to a MemoryStream for further transmission over a n...
validate-that-the-pixel-data-remains-unchanged-after-converting-a-dicom-image-to-png-format.csDicomImage, PngImage, PngOptionsValidate that the pixel data remains unchanged after converting a DICOM image to...
validate-that-the-generated-png-files-are-viewable-in-standard-image-viewers-after-conversion.csPngOptionsValidate that the generated PNG files are viewable in standard image viewers aft...
implement-asynchronous-dicom-to-png-conversion-using-task-run-to-avoid-blocking-the-ui-thread.csDicomImage, PngOptionsImplement asynchronous DICOM to PNG conversion using Task.Run to avoid blocking ...
create-a-command-line-tool-that-accepts-a-dicom-file-path-and-outputs-a-png-file-to-a-folder.csDicomImage, PngOptionsCreate a command‑line tool that accepts a DICOM file path and outputs a PNG file...
develop-a-unit-test-that-loads-a-sample-dicom-converts-it-to-png-and-compares-file-sizes.csPngOptionsDevelop a unit test that loads a sample DICOM, converts it to PNG, and compares ...
integrate-dicom-to-png-conversion-into-an-asp-net-core-api-endpoint-returning-the-png-as-a-byte-array.csDicomImage, PngOptionsIntegrate DICOM to PNG conversion into an ASP.NET Core API endpoint returning th...
create-a-windows-forms-application-that-allows-users-to-select-dicom-files-and-view-generated-png-previews.csPngOptionsCreate a Windows Forms application that allows users to select DICOM files and v...
write-a-powershell-script-that-invokes-the-net-conversion-library-to-process-dicom-files-in-bulk.csPngOptionsWrite a PowerShell script that invokes the .NET conversion library to process DI...
configure-the-png-output-to-include-metadata-from-the-original-dicom-file-for-traceability.csPngOptionsConfigure the PNG output to include metadata from the original DICOM file for tr...
extract-the-patient-name-tag-from-dicom-metadata-and-embed-it-into-the-png-file-name.csDicomImage, PngOptionsExtract the patient name tag from DICOM metadata and embed it into the PNG file ...
apply-a-custom-color-palette-to-the-png-output-when-converting-grayscale-dicom-images.csPngOptionsApply a custom color palette to the PNG output when converting grayscale DICOM i...
create-a-logging-wrapper-that-records-start-and-end-timestamps-for-each-dicom-to-png-conversion-operation.csDicomImage, PngOptionsCreate a logging wrapper that records start and end timestamps for each DICOM to...
develop-a-background-service-that-monitors-a-folder-for-new-dicom-files-and-automatically-converts-them-to-png.csDicomImage, PngOptionsDevelop a background service that monitors a folder for new DICOM files and auto...
document-the-conversion-process-in-code-comments-including-required-using-directives-and-disposal-patterns.csTiffOptionsDocument the conversion process in code comments, including required using direc...

Category Statistics

  • Total examples: 30
  • Failed: 0
  • Pass rate: 100.0%

Key API Surface

  • ApngOptions
  • DicomImage
  • DicomOptions
  • LoadOptions
  • MedianFilterOptions
  • PngImage
  • PngOptions
  • RasterImage
  • TiffOptions

Failed Tasks

All tasks passed ✅

Operations Covered

  • Convert grayscale DICOM to PNG with custom palette
  • Batch convert multiple DICOM files to PNG while preserving original filenames
  • Set PNG compression level to balance file size and quality
  • Convert a DICOM image stored in a byte‑array to PNG using MemoryStream (in‑memory processing)
  • Log start and end timestamps for each DICOM‑to‑PNG conversion page
  • Monitor a folder for new DICOM files and automatically convert them to PNG (background service)
  • Apply a custom color palette to PNG output when converting DICOM images
  • Convert JPEG images to TIFF format

Supported Formats

  • PNG – target format for all DICOM conversions and for JPEG‑to‑TIFF example (output)
  • DICOM – source medical image format being read and converted
  • JPEG – source format in the JPEG‑to‑TIFF example
  • TIFF – output format in the JPEG‑to‑TIFF example

API Classes Used

  • Image — base class that loads an image file (e.g., DICOM) and provides the Save method.
  • DicomImage — represents a DICOM image; used to access individual frames/pages and to perform conversion.
  • PngOptions — holds PNG‑specific saving options such as compression level and custom palette.
  • TiffOptions — holds TIFF‑specific saving options (used when converting JPEG to TIFF).
  • FileSystemWatcher — .NET class that watches a directory for new DICOM files and triggers conversion (used in the background‑service example).
  • MemoryStream — .NET stream used to hold a DICOM byte array in memory for conversion without touching the file system.
  • Directory / Path — .NET utilities for ensuring output folders exist (supporting the conversion workflow).

Use Cases

  • When you need to turn a grayscale DICOM scan into a PNG with a specific colour map, you can apply a custom palette during the conversion using Aspose.Imaging for .NET.
  • If you have a folder full of DICOM files and must output PNGs that keep the original filenames, a simple batch‑convert loop lets you preserve naming while processing each file.
  • To reduce the size of PNGs generated from DICOM images, you can set the PNG compression level in PngOptions before saving, balancing file size against visual quality.
  • When a DICOM image arrives as a byte array (for example from a web API), you can convert it to PNG entirely in memory by loading the bytes into a MemoryStream and saving with Aspose.Imaging in C#.
  • For developers searching “how to convert DICOM to PNG with Aspose.Imaging for .NET”, the examples demonstrate the full workflow: load the DICOM, configure conversion options, and save as PNG.

Related Categories

If you’re also working with other medical image formats, the Conversion category shows how to move between generic raster types, which can be combined with DICOM‑to‑PNG pipelines.
For scenarios where you need to further process the PNG output—such as applying filters or adjusting colour balance—see the Image And Photo Filters examples that operate on the same Image objects.
When your workflow involves converting the resulting PNGs to other raster formats (e.g., JPEG or TIFF), the Convert Raster Image category provides ready‑to‑use code snippets that complement the DICOM conversion steps.

Get Started

Ready to try Convert Dicom Images conversions on your own files with Aspose.Imaging for .NET?

dotnet add package Aspose.Imaging
ResourceLink
📖 Documentationdocs.aspose.com/imaging/net
📦 NuGet Packagewww.nuget.org/packages/aspose.imaging
🚀 Release Notesreleases.aspose.com/imaging/net
🌐 Online Appsproducts.aspose.app/imaging/family
🔑 Free Temporary Licensepurchase.aspose.com/temporary-license
🤝 Consulting (paid implementation help)consulting.aspose.com
<!-- AUTOGENERATED:START -->

Updated: 2026-09-16 | Run: 20260806_142654 | Examples: 30

<!-- AUTOGENERATED:END -->

Developer Q&A

Q: How can I apply a custom color palette when converting a grayscale DICOM image to PNG in C# with Aspose.Imaging?

Use PngOptions to set the Palette property with a custom ColorPalette before calling image.Save(outputPath, pngOptions). The DICOM image is loaded with Image.Load(inputPath). → See: apply-a-custom-color-palette-to-the-png-output-when-converting-grayscale-dicom-images.cs

Q: What is the easiest way to batch‑convert every DICOM file in a directory to PNG while preserving the original file names using Aspose.Imaging for .NET?

Iterate through Directory.GetFiles(inputDir, "*.dcm"), load each file with Image.Load, and save it as PNG using image.Save(Path.ChangeExtension(filePath, ".png"), new PngOptions()). This keeps the base name unchanged. → See: batch-convert-all-dicom-files-in-a-directory-to-png-format-while-preserving-original-filenames.cs

Q: How do I configure the PNG compression level in Aspose.Imaging to balance file size and image quality during DICOM‑to‑PNG conversion?

Create a PngOptions instance and set its CompressionLevel (0‑9) before saving the image, e.g., pngOptions.CompressionLevel = 6;. Then call image.Save(outputPath, pngOptions). → See: configure-png-compression-level-in-pngoptions-to-balance-file-size-and-image-quality-during-conversion.cs

Q: How can I convert a DICOM image that is stored in a byte array to PNG entirely in memory using Aspose.Imaging and C#?

Wrap the byte array in a MemoryStream, load the image with Image.Load(memoryStream), and save to another MemoryStream using image.Save(pngStream, new PngOptions()). The resulting PNG bytes are obtained from pngStream.ToArray(). → See: convert-a-dicom-image-stored-in-a-byte-array-to-png-by-using-memorystream-for-in-memory-processing.cs

Q: How can I implement a retry mechanism that attempts a DICOM‑to‑PNG conversion up to three times on transient errors with Aspose.Imaging?

Enclose the conversion code in a loop that catches ImageLoadException (or other transient exceptions) and retries up to three attempts, breaking on success. Use Image.Load and image.Save inside the try block. → See: implement-a-retry-mechanism-that-attempts-dicom-to-png-conversion-up-to-three-times-on-transient-errors.cs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.