Drawing Raster Images on Vector Images
Contents
[
Hide
]
Aspose.Imaging for Java supports drawing Raster(JPEG, GIF, TIFF, BMP) images to Vector(SVG, EMF, WMF) images. Raster images are based on pixels and thus lose clarity when scaled, while Vector based images can be scaled indefinitely without degrading quality.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |