Drawing Raster Images on Vector Images
Draw Raster Image on SVG
Using Aspose.Imaging for Java 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
String dir = "images/"; | |
RasterImage imageToDraw = (RasterImage)Image.load(dir + "asposenet_220_src01.png"); | |
try | |
{ | |
// Load the image for drawing on it (drawing surface) | |
SvgImage canvasImage = (SvgImage )Image.load(dir + "asposenet_220_src02.svg"); | |
try | |
{ | |
SvgGraphics2D graphics = new 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 not equal to the destination one, the drawn image is stretched horizontally and vertically. | |
graphics.drawImage( | |
new Rectangle(0, 0, imageToDraw.getWidth(), imageToDraw.getHeight()), | |
new Rectangle(67, 67, imageToDraw.getWidth(), imageToDraw.getHeight()), | |
imageToDraw); | |
// Save the result image | |
SvgImage resultImage = graphics.endRecording(); | |
try | |
{ | |
resultImage.save(dir + "asposenet_220_src02.DrawImage.svg"); | |
} | |
finally | |
{ | |
resultImage.close(); | |
} | |
} | |
finally | |
{ | |
canvasImage.close(); | |
} | |
} | |
finally | |
{ | |
imageToDraw.close(); | |
} |
Draw Raster Image on EMF
Using Aspose.Imaging for Java 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
String dir = "images/"; | |
RasterImage imageToDraw = (RasterImage)Image.load(dir + "asposenet_220_src01.png"); | |
try | |
{ | |
// Load the image for drawing on it (drawing surface) | |
EmfImage canvasImage = (EmfImage)Image.load(dir + "input.emf"); | |
try | |
{ | |
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.getWidth(), canvasImage.getHeight()), | |
new Rectangle(0, 0, imageToDraw.getWidth(), imageToDraw.getHeight()), | |
GraphicsUnit.Pixel); | |
// Save the result image | |
EmfImage resultImage = graphics.endRecording(); | |
try | |
{ | |
resultImage.save(dir + "input.DrawImage.emf"); | |
} | |
finally | |
{ | |
resultImage.close(); | |
} | |
} | |
finally | |
{ | |
canvasImage.close(); | |
} | |
} | |
finally | |
{ | |
imageToDraw.close(); | |
} |
Draw Raster Image on WMF
Using Aspose.Imaging for Java 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
String dir = "images/"; | |
// Load the image to be drawn | |
RasterImage imageToDraw = (RasterImage)Image.load(dir + "asposenet_220_src01.png"); | |
try | |
{ | |
// Load the image for drawing on it (drawing surface) | |
WmfImage canvasImage = (WmfImage)Image.load(dir + "asposenet_222_wmf_200.wmf"); | |
try | |
{ | |
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.getWidth(), canvasImage.getHeight()), | |
new Rectangle(0, 0, imageToDraw.getWidth(), imageToDraw.getHeight()), | |
GraphicsUnit.Pixel); | |
// Save the result image | |
WmfImage resultImage = graphics.endRecording(); | |
try | |
{ | |
resultImage.save(dir + "asposenet_222_wmf_200.DrawImage.wmf"); | |
} | |
finally | |
{ | |
resultImage.close(); | |
} | |
} | |
finally | |
{ | |
canvasImage.close(); | |
} | |
} | |
finally | |
{ | |
imageToDraw.close(); | |
} |