Work with SVG images, cropping EMF image and specify font folder for EMF to raster image conversion with Aspose.Imaging for .NET 3.7.0

Share on FacebookTweet about this on TwitterShare on LinkedIn

We are pleased to announce the release of Aspose.Imaging for .NET 3.7.0. The major development in this release is support for Scalable Vector Graphics image. This release allows you to Crop EMF Image. Support to specify font folder while converting EMF to raster image has also been incorporated in this release.

Support for SVG image

Aspose.Imaging for .Net now supports the SVG image format (.svg). SVG stands for Scalable Vector Graphics. Below provided sample code demonstrate how to convert a SVG file to PNG format.



//Declare variables to store file paths for input and output images
string sourceFile = @"G:\Input\SVG_images\sample.svg";
string destFolderPath = @"G:\Input\SVG_images\sample_svg_out.png";

//Load an existing image into an instance of SVG class
using (Aspose.Imaging.FileFormats.Svg.SvgImage image = (Aspose.Imaging.FileFormats.Svg.SvgImage)Aspose.Imaging.Image.Load(sourceFile))
{
    // create an instance of PNG options
    PngOptions pngOptions = new PngOptions();

    //Save the results to disk
    image.Save(destFolderPath, pngOptions);
}

Cropping EMF Image

Using Aspose.Imaging for .Net, developers can crop EMF metafile. Aspose.Imaging for .Net provides two different approaches for cropping image: by shifts and by rectangle. Below provided sample code demonstrate how to crop an EMF image by shifts.



// create an instance of Rasterization options
EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;

// create an instance of PNG options
PdfOptions pdfOptions = new PdfOptions();
pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;

//Declare variables to store file paths for input and output images
string filePath = @"TestEmfBezier.emf";
string outPath = filePath + ".pdf";

//Load an existing image into an instance of EMF class
using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
{
  using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
  {
    //Based on the shift values, apply the cropping on image
    //Crop method will shift the image bounds toward the center of image
    image.Crop(30, 40, 50, 60);

    // Set height and width
    pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
    pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;

    //Save the results to disk
    image.Save(outputStream, pdfOptions);
  }
}

Specify Font Folder While Converting EMF To Raster Image

Using Aspose.Imaging for .NET API, developers can specify font folder while converting EMF to raster image. Following is the code demonstrates how to specify font folder for EMF image to PNG image.



// create an instance of Rasterization options
EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;

// create an instance of PNG options
PngOptions pngOptions = new PngOptions();
pngOptions.VectorRasterizationOptions = emfRasterizationOptions;

string filePath = @"G:\Input\imaging_alphabet.emf";

// load an existing EMF image
using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
{
    image.CacheData();

    // set heigh and width 
    pngOptions.VectorRasterizationOptions.PageWidth = 300;
    pngOptions.VectorRasterizationOptions.PageHeight = 350;

    // reset font settings
    FontSettings.Reset();
    image.Save(filePath + "_default_fonts.png", pngOptions);

    // set font folder path
    string fontPath = @"G:\Input\Fonts";

    // initialize font list
    List fonts = new List(FontSettings.GetDefaultFontsFolders());

    // add new font path to font list
    fonts.Add(fontPath);

    // assign list of font folders to font settings
    FontSettings.SetFontsFolders(fonts.ToArray(), true);

    // save the EMF file to PNG image with new font
    image.Save(filePath + "_with_my_fonts.png", pngOptions);
}

Enhancements

Following enhancements have been introduced in this release.

  • Process of loading DICOM image has been improved.

  • Processing of Horizontal and Vertical resolution values of an image has been improved.

  • process of drawing image has been improved.

Please refer to the release notes of Aspose.Imaging for .NET 3.7.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.