Convert EMF, WMF and SVG Images Programmatically using C#

Convert SVG

Images are everywhere on the internet. Let us explore working with a few of the popular image formats including EMF, WMF, and SVG images. In this article, you will be considering the compression of EMF, WMF, and SVG vector images to EMZ, WMZ, and SVGZ respectively. Moreover, we will also learn how to convert EMF, WMF, and SVG vector images to raster images such as PNG using C#. Following are the use cases we will be exploring:

Vector image files are often huge in size so the compression and uncompression of such images are helpful when you need to transfer files over a network. Let us learn the conversions with Aspose.Imaging for .NET API.

Convert EMF to EMZ using C#

EMZ file is actually the compressed form of EMF image. You can convert EMF to EMZ by following below steps:

  1. Load source EMF image
  2. Initialize VectorRasterizationOptions object
  3. Save image while specifying EmfOptions

Below code snippet shows how to convert an EMF to EMZ using C#:

Convert EMZ to EMF using C#

If you have received a compressed EMZ file and then you want to convert EMZ to EMF then follow the steps below:

  1. Load source EMZ file
  2. Initialize EmfRasterizationOptions object
  3. Save image while specifying EmfOptions

The code snippet below explains how to convert EMZ to EMF using C#:

Convert WMF to WMZ using C#

You can compress WMF images with Aspose.Imaging for .NET API. The compression process converts WMF to WMZ by following below steps:

  1. Load source WMF file
  2. Initialize WmfRasterizationOptions object
  3. Save the image using WmfOptions

Below code snippet shows how to convert WMF to WMZ using C#:

Convert WMZ to WMF using C#

As we have already learned to compress WMF image. Aspose.Imaging for .NET API lets you uncompress WMZ files and convert such WMZ to WMF file. You should follow the following steps for conversion:

  1. Load input WMZ file
  2. Declare an instance of WmfRasterizationOptions class
  3. Save output image as WMF file

The code snippet below shows how to convert WMZ to WMF using C#:

Convert SVG to SVGZ using C#

SVG images are widely used to display high quality and complex graphics. You can compress such vector images and convert SVG to SVGZ with below steps:

  1. Load input SVG file
  2. Initialize VectorRasterizationOptions object
  3. Save output SVGZ image using SvgOptions

Following code snippet shows how to convert SVG to SVGZ using C#:

Convert SVGZ to SVG using C#

You can uncompress an SVGZ file and convert an SVGZ to SVG with simple steps below:

  1. Load input SVGZ file
  2. Specify SvgRasterizationOptions instance
  3. Save SVG image with SvgOptions

The following code snippet shows how to convert SVGZ to SVG using C#:

So you have learned how to compress and uncompress vector format images including EMZ, WMZ and, SVGZ images. Let us move forward and understand how to convert such image files to raster images.

Convert EMZ to PNG using C#

EMZ is the compressed form of EMF image. You can directly convert it to a raster image format like PNG or JPG. You do not need to uncompress the image first and then convert it. Please follow below steps to convert EMZ to PNG image:

  1. Load input EMZ image
  2. Initialize an instance of VectorRasterizationOptions Class
  3. Save putput PNG image with PngOptions

The code snippet below shows how to convert EMZ to PNG image using C#:

Convert WMZ to PNG using C#

Now, let us learn the conversion of compressed WMF files, WMZ, directly to PNG. Below steps convert WMZ to PNG:

  1. Load source WMZ image file
  2. Declare an object of VectorRasterizationOptions class
  3. Save PNG image file using PngOptions class

The below code snippet follows these steps and shows how to convert WMZ to PNG using C#:

Convert SVGZ to PNG using C#

The exciting feature of SVGZ to PNG conversion has been introduced based on several requests from our customers. This feature lets you efficiently convert SVGZ to PNG images with high fidelity results. All you need to do is to follow the steps below:

The code snippet below is based on these steps which explain how to convert SVGZ to PNG with C#:

Conclusion

We have discussed the compression and uncompression of vector image formats which is helpful for transferring files. The approach is also suitable when you want to archive such images. For example, you can compress such vector images before archiving and later uncompress as per your requirements. Moreover, we have also explored the conversion of compressed vector images to raster images with Aspose.Imaging for .NET API. Furthermore, you may explore API Reference and API Documentation. Feel free to contact us at the Free Support Forum in case of any concern.

See Also

Generate HTML5 Canvas Programmatically using C#