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
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository17 other files it gives its agents.
- aspose-imaging-examplesAGENTS.md
- conversionAGENTS.md
- convert-apngAGENTS.md
- convert-cdrAGENTS.md
- convert-cmx-imagesAGENTS.md
- convert-eps-imagesAGENTS.md
- converting-wmf-and-emfAGENTS.md
- convert-open-document-graphicsAGENTS.md
- convert-raster-imageAGENTS.md
- convert-svg-to-raster-imagesAGENTS.md
- convert-webp-imagesAGENTS.md
- image-and-photo-filtersAGENTS.md
- kernel-filtersAGENTS.md
- manipulate-different-image-file-formatsAGENTS.md
- manipulating-imagesAGENTS.md
- merge-imagesAGENTS.md
- working-with-drawing-imagesAGENTS.md
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
- Distinctive: line 118
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 …
- Distinctive: line 119
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 …
- Very specific: line 121
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 …
- Distinctive: line 125
If you’re also working with other medical image formats, the Conversion category shows how to move between generic raster types, which can …
- Distinctive: line 127
When your workflow involves converting the resulting PNGs to other raster formats (e.g., JPEG or TIFF), the Convert Raster Image category …
- Very specific: line 154
Use PngOptions to set the Palette property with a custom ColorPalette before calling image.Save(outputPath, pngOptions).
- Very specific: line 160
Create a PngOptions instance and set its CompressionLevel (0‑9) before saving the image, e.g., pngOptions.CompressionLevel = 6;.
≈ “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.
Files
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-specificusing System;(30/30 files)using System.IO;(30/30 files)using Aspose.Imaging.ImageOptions;(30/30 files) ← category-specificusing Aspose.Imaging.FileFormats.Dicom;(22/30 files) ← category-specificusing Aspose.Imaging.FileFormats.Png;(7/30 files) ← category-specificusing Aspose.Imaging.CoreExceptions.ImageFormats;(2/30 files) ← category-specificusing Aspose.Imaging.ImageFilters.FilterOptions;(1/30 files) ← category-specificusing Aspose.Imaging.ProgressManagement;(1/30 files) ← category-specificusing Aspose.Imaging.CoreExceptions;(1/30 files) ← category-specificusing System.Threading.Tasks;(1/30 files)using Aspose.Imaging.FileFormats.Tiff.Enums;(1/30 files) ← category-specific
Files in this folder
| File | Key APIs | Description |
| load-a-dicom-file-from-disk-and-save-it-as-a-png-using-a-single-api-call.cs | DicomImage, PngOptions | Load 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.cs | DicomImage, LoadOptions, PngOptions | Convert 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.cs | DicomImage, PngOptions | Use 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.cs | DicomImage, MedianFilterOptions, PngOptions | Apply 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.cs | DicomImage, PngOptions | Resize 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.cs | PngOptions | Rotate 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.cs | PngOptions | Set 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.cs | PngOptions | Configure 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.cs | DicomImage, PngOptions | Iterate 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.cs | DicomImage, PngOptions | Batch 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.cs | DicomImage, LoadOptions, PngOptions | Implement 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.cs | PngOptions | Implement 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.cs | DicomImage, PngOptions | Implement 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.cs | PngOptions | Capture 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.cs | PngOptions | Use 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.cs | PngOptions | Save 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.cs | DicomImage, PngImage, PngOptions | Validate 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.cs | PngOptions | Validate 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.cs | DicomImage, PngOptions | Implement 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.cs | DicomImage, PngOptions | Create 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.cs | PngOptions | Develop 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.cs | DicomImage, PngOptions | Integrate 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.cs | PngOptions | Create 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.cs | PngOptions | Write 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.cs | PngOptions | Configure 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.cs | DicomImage, PngOptions | Extract 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.cs | PngOptions | Apply 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.cs | DicomImage, PngOptions | Create 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.cs | DicomImage, PngOptions | Develop 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.cs | TiffOptions | Document the conversion process in code comments, including required using direc... |
Category Statistics
- Total examples: 30
- Failed: 0
- Pass rate: 100.0%
Key API Surface
ApngOptionsDicomImageDicomOptionsLoadOptionsMedianFilterOptionsPngImagePngOptionsRasterImageTiffOptions
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 theSavemethod.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
PngOptionsbefore 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
MemoryStreamand 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| Resource | Link |
| 📖 Documentation | docs.aspose.com/imaging/net |
| 📦 NuGet Package | www.nuget.org/packages/aspose.imaging |
| 🚀 Release Notes | releases.aspose.com/imaging/net |
| 🌐 Online Apps | products.aspose.app/imaging/family |
| 🔑 Free Temporary License | purchase.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
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
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.

