| User Guide > How to Work with... > Formats with Additional Functionality > Vector Formats > Rasterizing a Vector Drawing |
To rasterize a vector drawing, use the Rasterize Method of ImGearVectorPage Class. This creates a copy of the drawing in bitmap form. For example:
| C# |
Copy Code |
|---|---|
if (igPage is ImGearVectorPage) igPage = ((ImGearVectorPage)igPage).Rasterize(); | |
To control the size of the rasterized bitmap, you can do one of following:
![]() |
SVG cannot be resized before it's rasterized; SVG doesn't have control parameters, and cannot be resized using the Resize Method. To resize an SVG, you need to rasterize it first, then resize it. |
| C# |
Copy Code |
|---|---|
using System.IO; using ImageGear.Core; using ImageGear.Formats; public ImGearPage ResizeDWGWithControlParameterAndRasterize(string fileDwg) { // Get all available format filters for DWG. IImGearFormat format = ImGearFileFormats.Filters.Get(ImGearFormats.DWG); // Set width in pixels. format.Parameters.GetByName("Width").Value = 320; ImGearVectorPage vectorPage = null; ImGearPage rasterPage = null; using (FileStream stream = new FileStream(fileDwg, FileMode.Open, FileAccess.Read)) { // Load DWG. vectorPage = (ImGearVectorPage)ImGearFileFormats.LoadPage(stream, 0); // Rasterize using set width. rasterPage = vectorPage.Rasterize(); } return rasterPage; } | |
| VB.NET |
Copy Code |
|---|---|
Imports System.IO
Imports ImageGear.Core
Imports ImageGear.Formats
Function ResizeDWGWithControlParameterAndRasterize(fileDwg As String) As ImGearPage
' Get all available format filters for DWG.
Dim format As IImGearFormat = ImGearFileFormats.Filters.Get(ImGearFormats.DWG)
' Set width in pixels.
format.Parameters.GetByName("Width").Value = 320
Dim vectorPage As ImGearVectorPage = Nothing
Dim rasterPage As ImGearPage = Nothing
Using stream As FileStream = New FileStream(fileDwg, FileMode.Open, FileAccess.Read)
' Load DWG.
vectorPage = CType(ImGearFileFormats.LoadPage(stream, 0), ImGearVectorPage)
' Rasterize using set width.
rasterPage = vectorPage.Rasterize()
End Using
Return rasterPage
End Function | |
| C# |
Copy Code |
|---|---|
using System.IO; using ImageGear.Core; using ImageGear.Formats; using ImageGear.Processing; public ImGearPage RasterizeAndResizeDWG(string fileDwg, int width) { ImGearVectorPage vectorPage = null; ImGearPage rasterPage = null; using (FileStream stream = new FileStream(fileDwg, FileMode.Open, FileAccess.Read)) { // Load DWG. vectorPage = (ImGearVectorPage)ImGearFileFormats.LoadPage(stream, 0); // Resize to given width using Bicubic Interpolation. int newHeight = width * vectorPage.DIB.Height / vectorPage.DIB.Width; ImGearBicubicInterpolationOptions igBicubicInterpolationOptions = new ImGearBicubicInterpolationOptions(); igBicubicInterpolationOptions.Sharpness = 1.5; ImGearProcessing.Resize(vectorPage, width, newHeight, igBicubicInterpolationOptions); // Rasterize using set width. rasterPage = vectorPage.Rasterize(); } return rasterPage; } | |
| VB.NET |
Copy Code |
|---|---|
Imports System.IO
Imports ImageGear.Core
Imports ImageGear.Formats
Imports ImageGear.Processing
Function RasterizeAndResizeDWG(fileDwg As String, width As Integer) As ImGearPage
Dim vectorPage As ImGearVectorPage = Nothing
Dim rasterPage As ImGearPage = Nothing
Using stream As FileStream = New FileStream(fileDwg, FileMode.Open, FileAccess.Read)
' Load DWG.
vectorPage = CType(ImGearFileFormats.LoadPage(stream, 0), ImGearVectorPage)
' Resize to given width using Bicubic Interpolation.
Dim newHeight As Integer = width * vectorPage.DIB.Height / vectorPage.DIB.Width
Dim igBicubicInterpolationOptions As ImGearBicubicInterpolationOptions = New ImGearBicubicInterpolationOptions()
igBicubicInterpolationOptions.Sharpness = 1.5
ImGearProcessing.Resize(vectorPage, width, newHeight, igBicubicInterpolationOptions)
' Rasterize using set width.
rasterPage = vectorPage.Rasterize()
End Using
Return rasterPage
End Function | |