To rasterize a vector drawing, use the Rasterize Method of ImGearVectorPage Class. This creates a copy of the drawing in bitmap format. 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.
- Before loading the vector drawing, set the Width filter control parameter of the format filter used to load the drawing to the desired width of the rasterized image in pixels. The height will be calculated automatically based on the aspect ratio of the drawing. When a width is not specified, the default is used, which is defined by the file format (see File Formats Reference).
C# |
Copy Code |
using System.IO;
using ImageGear.Core;
using ImageGear.Formats;
public ImGearPage ResizeDWFWithControlParameterAndRasterize(string fileDwf)
{
// Get all available format filters for DWF.
IImGearFormat format = ImGearFileFormats.Filters.Get(ImGearFormats.DWF);
// Set width in pixels.
format.Parameters.GetByName("Width").Value = 320;
ImGearVectorPage vectorPage = null;
ImGearPage rasterPage = null;
using (FileStream stream = new FileStream(fileDwf, FileMode.Open, FileAccess.Read))
{
// Load DWF.
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 ResizeDWFWithControlParameterAndRasterize(fileDwf As String) As ImGearPage
' Get all available format filters for DWF.
Dim format As IImGearFormat = ImGearFileFormats.Filters.Get(ImGearFormats.DWF)
' 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(fileDwf, FileMode.Open, FileAccess.Read)
' Load DWF.
vectorPage = CType(ImGearFileFormats.LoadPage(stream, 0), ImGearVectorPage)
' Rasterize using set width.
rasterPage = vectorPage.Rasterize()
End Using
Return rasterPage
End Function |
- Call the Resize Method of ImGearProcessing Class before calling the Rasterize Method. This will allow you to specify the rasterized dimensions in pixels.
C# |
Copy Code |
using System.IO;
using ImageGear.Core;
using ImageGear.Formats;
using ImageGear.Processing;
public ImGearPage RasterizeAndResizeDWF(string fileDwf, int width)
{
ImGearVectorPage vectorPage = null;
ImGearPage rasterPage = null;
using (FileStream stream = new FileStream(fileDwf, FileMode.Open, FileAccess.Read))
{
// Load DWF.
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 RasterizeAndResizeDWF(fileDwf As String, width As Integer) As ImGearPage
Dim vectorPage As ImGearVectorPage = Nothing
Dim rasterPage As ImGearPage = Nothing
Using stream As FileStream = New FileStream(fileDwf, FileMode.Open, FileAccess.Read)
' Load DWF.
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 |