Ikram ul Haq November 1, 2016one Comment

Create WMF metafile image with Aspose.Imaging for .NET 16.10

Create WMF metafile image with Aspose.Imaging for .NET 16.10

November 1, 2016
Share on FacebookTweet about this on TwitterShare on LinkedIn

We are pleased to announce the release of Aspose.Imaging for .NET 16.10. The major development in this release is support for creating WMF metafile image. Support to convert WMF metafile to SVG format has also been incorporated in this release.

Create EMF Metafile Image

Aspose.Imaging for .Net now supports creating WMF metafile image. Aspose.Imaging for .Net provides the WmfRecorderGraphics2D class to create WMF metafile. Below provided sample code demonstrates how to create WMF metafile.



// WmfRecorderGraphics2D class provides you the frame or canvas to draw shapes on it.
// Create an instance of WmfRecorderGraphics2D class. The constructor takes in 2 parameters:
// 1. Instance of Imaging Rectangle class
// 2. An integer value for inches
Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D graphics = new Aspose.Imaging.FileFormats.Wmf.Graphics.WmfRecorderGraphics2D(new Aspose.Imaging.Rectangle(0, 0, 100, 100), 96);
            
// Define background color
graphics.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;

//Init
// Create an instance of Imaging Pen class and mention its color.
Aspose.Imaging.Pen pen = new Aspose.Imaging.Pen(Aspose.Imaging.Color.Blue);

// Create an instance of Imaging Brush class and mention its color.
Aspose.Imaging.Brush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.YellowGreen);
            
            
//Polygon
// Fill polygon by calling FillPolygon method and passing parameters brush and points.
graphics.FillPolygon(brush, new Aspose.Imaging.Point[] { new Aspose.Imaging.Point(2, 2), new Aspose.Imaging.Point(20, 20), new Aspose.Imaging.Point(20, 2) });

// Draw a polygon by calling DrawPolygon method and passing parameters pen and points.
graphics.DrawPolygon(pen, new Aspose.Imaging.Point[] { new Aspose.Imaging.Point(2, 2), new Aspose.Imaging.Point(20, 20), new Aspose.Imaging.Point(20, 2) });

//Ellipse
// Create an instance of HatchBrush class set different properties.
brush = new HatchBrush() { HatchStyle = HatchStyle.Cross, BackgroundColor = Aspose.Imaging.Color.White, ForegroundColor = Aspose.Imaging.Color.Silver };

// Fill ellipse by calling FillEllipse method and passing parameters brush and an instance of Imaging Rectangle class.
graphics.FillEllipse(brush, new Aspose.Imaging.Rectangle(25, 2, 20, 20));

// Draw an ellipse by calling DrawEllipse method and passing parameters pen and an instance of Imaging Rectangle class.
graphics.DrawEllipse(pen, new Aspose.Imaging.Rectangle(25, 2, 20, 20));

//Arc
// Define pen style by setting DashStyle value
pen.DashStyle = Aspose.Imaging.DashStyle.Dot;

// Set color of the pen
pen.Color = Aspose.Imaging.Color.Black;

// Draw an Arc by calling DrawArc method and passing parameters pen and an instance of Imaging Rectangle class.
graphics.DrawArc(pen, new Aspose.Imaging.Rectangle(50, 2, 20, 20), 0, 180);

//CubicBezier
pen.DashStyle = Aspose.Imaging.DashStyle.Solid;
pen.Color = Aspose.Imaging.Color.Red;

// Draw an CubicBezier by calling DrawCubicBezier method and passing parameters pen and points.
graphics.DrawCubicBezier(pen, new Aspose.Imaging.Point(10, 25), new Aspose.Imaging.Point(20, 50), new Aspose.Imaging.Point(30, 50), new Aspose.Imaging.Point(40, 25));

//Image
// Create an Instance of Image class.
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"TextureBrushPattern.png"))
{
    // Cast the instance of image class to RasterImage.
    Aspose.Imaging.RasterImage rasterImage = image as Aspose.Imaging.RasterImage;
    if (rasterImage != null)
    {
        // Draw an image by calling DrawImage method and passing parameters rasterimage and point.
        graphics.DrawImage(rasterImage, new Aspose.Imaging.Point(50, 50));
    }
}

//Line
// Draw a line by calling DrawLine method and passing x,y coordinates of 1st point and same for 2nd point along with color infor as Pen.
graphics.DrawLine(pen, new Aspose.Imaging.Point(2, 98), new Aspose.Imaging.Point(2, 50));

//Pie
// Define settings of the brush object.
brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Green);
pen.Color = Aspose.Imaging.Color.DarkGoldenrod;

// Fill pie by calling FillPie method and passing parameters brush and an instance of Imaging Rectangle class.
graphics.FillPie(brush, new Aspose.Imaging.Rectangle(2, 38, 20, 20), 0, 45);

// Draw pie by calling DrawPie method and passing parameters pen and an instance of Imaging Rectangle class.
graphics.DrawPie(pen, new Aspose.Imaging.Rectangle(2, 38, 20, 20), 0, 45);

            
pen.Color = Aspose.Imaging.Color.AliceBlue;

//Polyline
// Draw Polyline by calling DrawPolyline method and passing parameters pen and points.
graphics.DrawPolyline(pen, new Aspose.Imaging.Point[] { new Aspose.Imaging.Point(50, 40), new Aspose.Imaging.Point(75, 40), new Aspose.Imaging.Point(75, 45), new Aspose.Imaging.Point(50, 45) });

// For having Strings
// Create an instance of Font class.
Aspose.Imaging.Font font = new Aspose.Imaging.Font("Arial", 16);

// Draw String by calling DrawString method and passing parameters string to display, color and X & Y coordinates.
graphics.DrawString("Aspose", font, Aspose.Imaging.Color.Blue, 25, 75);

// Call end recording of graphics object and save WMF image by calling Save method.
using (Aspose.Imaging.FileFormats.Wmf.WmfImage image = graphics.EndRecording())
{
    image.Save(@"TestGraphicDrawing.wmf");
}

Convert WMF To SVG

Using Aspose.Imaging for .Net developers can convert WMF to SVG format. Aspose.Imaging for .Net provides SvgOptions class to create SVG format image. Below is the code demonstration of the said functionality.



// Path & Name of input file
string inputFileName = @"test.wmf";

// Path & Name of output file
string outputFileName = inputFileName + ".svg";

// Create an instance of Image class by loading an existing .
using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(inputFileName))
{
    // Create an instance of EmfRasterizationOptions class.
    Aspose.Imaging.ImageOptions.EmfRasterizationOptions options = new Aspose.Imaging.ImageOptions.EmfRasterizationOptions();
    options.PageWidth = image.Width;
    options.PageHeight = image.Height;

    // Call save method to convert WMF to SVG format by passing output file name and SvgOptions class instance.
    image.Save(outputFileName, new Aspose.Imaging.ImageOptions.SvgOptions() { VectorRasterizationOptions = options });
}

Enhancements

Following enhancements have been introduced in this release.

  • Process of converting GIF to TIFF has been improved.

  • Process of generating EMF image has been improved.

  • Process of resizing proportional height has been improved.

  • Functionality of Save() method for PSD file has been improved.

  • Functionality to update text in PSD layer has been improved.

  • Process of converting WMF to PNG image has been improved.

  • Functionality to process DICOM image has been improved.

  • Functionality to export EMF+ metafile to PDF format has been improved.

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

Join the Conversation

1 Comment

Leave a comment

Posted inAspose.Imaging Product Family
 

Related Articles