Working with Aspose.Imaging for .NET

Aspose
Posted by in ASP.NET category on for Intermediate level | Points: 250 | Views : 1314 red flag
Rating: 4.25 out of 5  
 4 vote(s)

In this article, we shall learn how to work with Aspose.Imaging API. Aspose.Imaging for .NET is an advanced image processing API that lets developers create, edit, draw or convert images in their .NET applications.

Aspose.Imaging for .NET

Aspose.Imaging for .NET is an advanced image processing API that lets developers create, edit, draw or convert images in their .NET applications. It works independent of other applications and allows saving to Adobe Photoshop® format (PSD) without having Photoshop or any other image editor installed on the machine.. A new version of Aspose.Imaging has been released and the major development is to convert metafile (Emf/Emf+) to raster image formats. Additionally support to merge PSD layers while converting PSD to JPG has also been incorporated in this release.

Export Metafile to Raster Formats

Using Aspose.Imaging for .NET, developers can convert metafile (Emf/Emf+) to raster formats. Aspose.Imaging for .Net provides the EmfImage class to load EMF files and same can be used to convert the PSD to raster formats. Below provided sample code demonstrate how to convert an EMF file to different raster formats.

string filePath = "TestEmfBezier.emf";

// Create EmfRasterizationOption class instance and set properties
EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.PapayaWhip;
emfRasterizationOptions.PageWidth = 300;
emfRasterizationOptions.PageHeight = 300;

// Load an existing EMF file as iamge and convert it to EmfImage class object
using (var image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
{
    if (!image.Header.EmfHeader.Valid)
    {
        throw new Aspose.Imaging.CoreExceptions.ImageLoadException(string.Format("The file {0} is not valid", filePath));
    }

    // Convert EMF to BMP
    image.Save(filePath + ".bmp", new BmpOptions() { VectorRasterizationOptions = emfRasterizationOptions });

    // Convert EMF to GIF
    image.Save(filePath + ".gif", new GifOptions() { VectorRasterizationOptions = emfRasterizationOptions });

    // Convert EMF to JPEG
    image.Save(filePath + ".jpeg", new JpegOptions() { VectorRasterizationOptions = emfRasterizationOptions });

    // Convert EMF to J2K
    image.Save(filePath + ".j2k", new Jpeg2000Options() { VectorRasterizationOptions = emfRasterizationOptions });

    // Convert EMF to PNG
    image.Save(filePath + ".png", new PngOptions() { VectorRasterizationOptions = emfRasterizationOptions });

    // Convert EMF to PSD
    image.Save(filePath + ".psd", new PsdOptions() { VectorRasterizationOptions = emfRasterizationOptions });

    // Convert EMF to TIFF
    image.Save(filePath + ".tiff", new TiffOptions(TiffExpectedFormat.TiffLzwRgb) { VectorRasterizationOptions = emfRasterizationOptions });

    // Convert EMF to WebP
    image.Save(filePath + ".webp", new WebPOptions() { VectorRasterizationOptions = emfRasterizationOptions });
}
Merge PSD Layers

Using Aspose.Imaging for .NET API, developers can
merge layers in a PSD file while converting PSD file to JPG. The following code example demonstrates how to merge layers of a PSD file

string sourceFileName = "5_layers.psd";

//Load an existing PSD file as image
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(sourceFileName))
{
       // Convert the loaded image to PSDImage
       var psdImage = (Aspose.Imaging.FileFormats.Psd.PsdImage)image;

       // create a JPG file stream
       using (Stream stream = File.Create(sourceFileName.Replace("psd", "jpg")))
       {

             // Create JPEG option class object
             var jpgOptions = new JpegOptions();

            // Set the source property to jpg file stream.
            jpgOptions.Source = new Aspose.Imaging.Sources.StreamSource(stream);

            // call the Save the method of PSDImage class to merge the layers and save it as jpg image.
            psdImage.Save(stream, jpgOptions);
       }
}
Enhancements

Following enhancements have been introduced in this release.
  • Process to convert PSD to TIFF format has been improved.
  • Memory management process while rendering metafiles has been improved.
Please refer to the release notes of Aspose.Imaging for .NET 3.6.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.
Page copy protected against web site content infringement by Copyscape

About the Author

Aspose
Full Name: Aspose .com
Member Level: Starter
Member Status: Member
Member Since: 9/20/2015 8:35:20 PM
Country: Australia



Login to vote for this post.

Comments or Responses

Posted by: Bhuvanesh6 on: 7/21/2016 | Points: 25
Nice to know about this Aspose Imaging

Login to post response

Comment using Facebook(Author doesn't get notification)