Work with DICOM images and convert EMF to PDF using Aspose.Imaging for .NET 3.5.0

Share on FacebookTweet about this on TwitterShare on LinkedIn

We are pleased to announce the release of Aspose.Imaging for .NET 3.5.0. The major development in this release is support for DICOM image and support for EMF format. This release allows you to blur an image and import image to PSD layer. Support to apply correction filters on images has also been incorporated in this release.

Support for DICOM image

Aspose.Imaging for .Net now supports the DICOM image format(.dicom). DICOM stands for Digital Imaging and Communications in Medicine. DICOM is a standard for handling, storing, printing, and transmitting information in medical imaging. It includes a file format definition and a network communications protocol. Following is the list of operations that can be performed on a DICOM image using Aspose.Imaging:

Converting EMF To PDF

Using Aspose.Imaging for .Net, developers can convert EMF metafile to PDF format. Aspose.Imaging for .Net provides the EmfImage class to load EMF files and same can be used to save the image to PDF format. Below provided sample code demonstrate how to convert EMF to PDF.


string[] filePaths = new string[] 
{
    "FilledRectangleRotateMode_c.emf",
    "image5.emf",
    "LinearGradientBrushCircuitMode.emf",
    "Pict.emf",
    "Picture1.emf",
    "test.emf",
    "wrong-font-size.emf"
};

foreach (string filePath in filePaths)
{
    string outPath = filePath + ".pdf";

    using (var image = (EmfImage)Image.Load(filePath))
    using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
    {
        if(!image.Header.EmfHeader.Valid)
        {
           throw new ImageLoadException(string.Format("The file {0} is not valid", outPath));
        }

        EmfRasterizationOptions emfRasterization = new EmfRasterizationOptions();
        emfRasterization.PageWidth = image.Width;
        emfRasterization.PageHeight = image.Height;
        emfRasterization.BackgroundColor = Color.WhiteSmoke;

        PdfOptions pdfOptions = new PdfOptions();
        pdfOptions.VectorRasterizationOptions = emfRasterization;

        image.Save(outputStream, pdfOptions);
    }
}

Blur An Image

Using Aspose.Imaging for .NET API, developers can create blur effect on an image. Following is the code demonstrating the use of GaussianBlurFilterOptions class.



//Declare variables to store file paths for input and output images
string sourcePath = @"D:\blur_test_before.jpg";
string outPath = @"D:\blur_test_after.jpg";

// Load an image 
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourcePath))
{
    //Convert the image into RasterImage.
    Aspose.Imaging.RasterImage rasterImage = (Aspose.Imaging.RasterImage)image;

    //Pass Bounds[rectangle] of image and GaussianBlurFilterOptions instance to Filter method.
    rasterImage.Filter(rasterImage.Bounds, new Aspose.Imaging.ImageFilters.FilterOptions.GaussianBlurFilterOptions(5, 5));

    //Save the results to output path.
    rasterImage.Save(outPath);
}

Import Image To PSD Layer

Using Aspose.Imaging for .NET API, developers can import image into a PSD file. Aspose.Imaging for .NET has exposed the DrawImage method of the Layer class to add/import an image into a PSD file. DrawImage method needs location and image values to add/import an image into a PSD file. The following code example demonstrates how to import an image into PSD file.


//Declare variables to store file paths for input and output.
string sourceFileName = "source.psd";
string outputFileName = "result.psd";

// Load a PSD file as an image and caste it into PsdImage
using (Aspose.Imaging.FileFormats.Psd.PsdImage image = (Aspose.Imaging.FileFormats.Psd.PsdImage)Aspose.Imaging.Image.Load(sourceFileName))
{
     // Extract a layer from PSDImage
     Aspose.Imaging.FileFormats.Psd.Layers.Layer layer = image.Layers[1];

     // Load the image that is needed to be imported into the PSD file.
     string normalImagePath = "png_normal.png";
     using (RasterImage drawImage = (RasterImage)Aspose.Imaging.Image.Load(normalImagePath))
     {
           // Call DrawImage method of the Layer class and pass the image instance.
           layer.DrawImage(new Aspose.Imaging.Point(10, 10), drawImage);
     }

     //Save the results to output path.
     image.Save(outputFileName, new PsdOptions());
}

Apply Correction Filter On An Image

Using Aspose.Imaging for .NET API, developers can apply correction filters on an image. Aspose.Imaging for .NET has exposed the BilateralSmoothingFilterOptions and SharpenFilterOptions classes for filtration. BilateralSmoothingFilterOptions class needs an integer as size. The following code example demonstrates how to apply correction filter.


//Declare variables to store file paths for input and output images
string inputFilePath = @"D:\a1.jpg";
string outputFilePath = @"D:\a1_out.jpg";

// Load an image 
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFilePath))
{
    //Convert the image into RasterImage.
    RasterImage rasterImage = image as RasterImage;
    if (rasterImage == null)
    {
        return;
    }

    //Get Bounds[rectangle] of image.
    Aspose.Imaging.Rectangle rect = image.Bounds;

    // Create an instance of BilateralSmoothingFilterOptions class with size parameter.
    Aspose.Imaging.ImageFilters.FilterOptions.BilateralSmoothingFilterOptions bilateralOptions = new Aspose.Imaging.ImageFilters.FilterOptions.BilateralSmoothingFilterOptions(3);

    // Create an instance of SharpenFilterOptions class.
    Aspose.Imaging.ImageFilters.FilterOptions.SharpenFilterOptions sharpenOptions = new Aspose.Imaging.ImageFilters.FilterOptions.SharpenFilterOptions();
                
    // Supply the filters to raster image.
    rasterImage.Filter(rect, bilateralOptions);
    rasterImage.Filter(rect, sharpenOptions);
                
    // Adjust the contrast accordingly.
    rasterImage.AdjustContrast(-10);

    // Set brightness using Binarize Bradley
    rasterImage.BinarizeBradley(80);

    //Save the results to output path.
    rasterImage.Save(outputFilePath);
}

Enhancements

Following enhancements have been introduced in this release.

  • Process of digital signing of assembly has been improved.

  • Processing of PSD file has been improved.

  • DXF to PDF conversion process has been improved.

  • JPG to JPG2000 format conversion process has been improved.

  • Processing of YCBCR format has been upgraded.

  • Processing of JPEG & TIFF formats have been improved.

Please refer to the release notes of Aspose.Imaging for .NET 3.5.0 for a full view of improvements along with sample code snippets for newly added features. If you are planning to upgrade the API to the latest revision, we strongly suggest you to check the Public API Change section to know what has been changed in the public API since your current version.

Aspose.Imaging for .Net Resources

The resources, you may need to accomplish your tasks:

As always we appreciate your feedback so if you ever have anything to tell us about this release or anything else, please head to the Aspose.Imaging forum for a chat.