Drawing Raster Images on Vector Images
Draw Raster Image on SVG
Using Aspose.Imaging for .NET you can draw raster image on SVG. With a few simple steps, you will be able to draw an existing raster image on a vector file.
- Load a raster image using the factory method Load exposed by Image class.
- Load a SVG image
- Draw a rectangular part of the raster image within the specified bounds of the vector image
- Save the results
using Aspose.Imaging; | |
using Aspose.Imaging.Brushes; | |
using Aspose.Imaging.FileFormats.Svg; | |
using Aspose.Imaging.ImageOptions; | |
using Aspose.Imaging.Shapes; | |
using Aspose.Imaging.Sources; | |
using System; | |
using System.IO; | |
string templatesFolder = @"c:\Users\USER\Downloads\templates\"; | |
string dataDir = templatesFolder; | |
// Load the image to be drawn | |
using (RasterImage imageToDraw = (RasterImage)Image.Load(dataDir + "template.png")) | |
{ | |
// Load the image for drawing on it (drawing surface) | |
using (SvgImage canvasImage = (SvgImage)Image.Load(dataDir + "template.svg")) | |
{ | |
// Drawing on an existing Svg image. | |
Aspose.Imaging.FileFormats.Svg.Graphics.SvgGraphics2D graphics = new Aspose.Imaging.FileFormats.Svg.Graphics.SvgGraphics2D(canvasImage); | |
// Draw a rectagular part of the raster image within the specified bounds of the vector image (drawing surface). | |
// Note that because the source size is equal to the destination one, the drawn image is not stretched. | |
graphics.DrawImage( | |
new Rectangle(0, 0, imageToDraw.Width, imageToDraw.Height), | |
new Rectangle(67, 67, imageToDraw.Width, imageToDraw.Height), | |
imageToDraw); | |
// Save the result image | |
using (SvgImage resultImage = graphics.EndRecording()) | |
{ | |
resultImage.Save(dataDir + "result.svg"); | |
} | |
} | |
} | |
File.Delete(dataDir + "result.svg"); |
Draw Raster Image on EMF
Using Aspose.Imaging for .NET you can draw raster image on EMF. With a few simple steps, you will be able to draw an existing raster image on a vector file.
- Load a raster image using the factory method Load exposed by Image class.
- Load a EMF image
- Draw a rectangular part of the raster image within the specified bounds of the vector image
- Save the results
using Aspose.Imaging; | |
using Aspose.Imaging.Brushes; | |
using Aspose.Imaging.FileFormats.Emf; | |
using Aspose.Imaging.FileFormats.Emf.Graphics; | |
using Aspose.Imaging.FileFormats.Svg; | |
using Aspose.Imaging.ImageOptions; | |
using Aspose.Imaging.Shapes; | |
using Aspose.Imaging.Sources; | |
using System; | |
using System.IO; | |
string templatesFolder = @"c:\Users\USER\Downloads\templates\"; | |
string dataDir = templatesFolder; | |
// Load the image to be drawn | |
using (RasterImage imageToDraw = (RasterImage)Image.Load(dataDir + "template.png")) | |
{ | |
// Load the image for drawing on it (drawing surface) | |
using (EmfImage canvasImage = (EmfImage)Image.Load(dataDir + "template.emf")) | |
{ | |
EmfRecorderGraphics2D graphics = EmfRecorderGraphics2D.FromEmfImage(canvasImage); | |
// Draw a rectagular part of the raster image within the specified bounds of the vector image (drawing surface). | |
// Note that because the source size is not equal to the destination one, the drawn image is stretched horizontally and vertically. | |
graphics.DrawImage( | |
imageToDraw, | |
new Rectangle(67, 67, canvasImage.Width, canvasImage.Height), | |
new Rectangle(0, 0, imageToDraw.Width, imageToDraw.Height), | |
GraphicsUnit.Pixel); | |
// Save the result image | |
using (EmfImage resultImage = graphics.EndRecording()) | |
{ | |
resultImage.Save(dataDir + "result.emf"); | |
} | |
} | |
} | |
File.Delete(dataDir + "result.emf"); |
Draw Raster Image on WMF
Using Aspose.Imaging for .NET you can draw raster image on WMF. With a few simple steps, you will be able to draw an existing raster image on a vector file.
- Load a raster image using the factory method Load exposed by Image class.
- Load a WMF image
- Draw a rectangular part of the raster image within the specified bounds of the vector image
- Save the results
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Wmf; | |
using Aspose.Imaging.FileFormats.Wmf.Graphics; | |
using System.IO; | |
string templatesFolder = @"c:\Users\USER\Downloads\templates\"; | |
string dataDir = templatesFolder; | |
// Load the image to be drawn | |
using (RasterImage imageToDraw = (RasterImage)Image.Load(dataDir + "template.png")) | |
{ | |
// Load the image for drawing on it (drawing surface) | |
using (WmfImage canvasImage = (WmfImage)Image.Load(dataDir + "template.wmf")) | |
{ | |
WmfRecorderGraphics2D graphics = WmfRecorderGraphics2D.FromWmfImage(canvasImage); | |
// Draw a rectagular part of the raster image within the specified bounds of the vector image (drawing surface). | |
// Note that because the source size is not equal to the destination one, the drawn image is stretched horizontally and vertically. | |
graphics.DrawImage( | |
imageToDraw, | |
new Rectangle(67, 67, canvasImage.Width, canvasImage.Height), | |
new Rectangle(0, 0, imageToDraw.Width, imageToDraw.Height), | |
GraphicsUnit.Pixel); | |
// Save the result image | |
using (WmfImage resultImage = graphics.EndRecording()) | |
{ | |
resultImage.Save(dataDir + "result.wmf"); | |
} | |
} | |
} | |
File.Delete(dataDir + "result.wmf"); |