GLG Toolkit, C# Class Library  Version 4.6
Printing and Image Generation

This group contains methods used for printing, generating PostScript output and saving images. More...

Detailed Description

This group contains methods used for printing, generating PostScript output and saving images.

Functions

Bitmap CreateImage (String resource_name)
 Creates and returns an image of the current state of the viewport's graphics. More...
 
Bitmap CreateImageCustom (String resource_name, System.Drawing.Rectangle image_area, int gap)
 Creates an image of the specified rectangular region of the viewport's graphics. More...
 
bool ExportPostScript (String file, double x, double y, double width, double height, bool portrait, bool stretch, bool center)
 Generates a PostScript output of the current state of the viewport's graphics. More...
 
bool NativePrint (Graphics graphics)
 Generates printing output of the current state of the viewport's graphics. More...
 
static bool SaveImage (Bitmap image, String image_file, System.Drawing.Imaging.ImageFormat image_format)
 Saves an image to a file in a requested format. More...
 

Function Documentation

◆ CreateImage()

Bitmap CreateImage ( String  resource_name)

Creates and returns an image of the current state of the viewport's graphics.

For a light viewport, the output will be generated for its parent viewport. The drawing's hierarchy must be set up in order to generate an image.

Parameters
resource_nameThe resource path of a child viewport whose image to generate, or null to generate the image of the viewport the method is invoked on. The resource path is relative to the invoking object.
Returns
Created image.

◆ CreateImageCustom()

Bitmap CreateImageCustom ( String  resource_name,
System.Drawing.Rectangle  image_area,
int  gap 
)

Creates an image of the specified rectangular region of the viewport's graphics.

For a light viewport, the output will be generated for its parent viewport. The drawing's hierarchy must be set up in order to generate an image.

Parameters
resource_nameThe resource path of a child viewport whose image to generate, or null to generate the image of the viewport the method is invoked on. The resource path is relative to the invoking object.
image_areaThe area used to generating an image of. The area is defined in screen pixels relative to the origin of the viewport's window, which has screen coordinates of (0,0).
gapSpecifies the padding space between the extent of the drawing and the border of the generated image in case when width and height of the image_area are set to zero, see below.

The extent of the image area may be obtained by querying the bounding box of either the whole drawing or of the area of the drawing for which the image needs to be generated using GetBox.

If width and height of the image_area are set to 0, the image of the whole drawing is generated using the drawing's bounding rectangle as the image generation area, without clipping to just the visible area. If the viewport is zoomed in, this area may be significantly bigger than the visible area of the viewport, and the image size may be quite large. The viewport's zoom factor defines the scaling factor for objects in the drawing when the image is saved.

Returns
Created image.

◆ ExportPostScript()

bool ExportPostScript ( String  file,
double  x,
double  y,
double  width,
double  height,
bool  portrait,
bool  stretch,
bool  center 
)

Generates a PostScript output of the current state of the viewport's graphics.

If the object is a light viewport, the output will be generated for its parent viewport.

Parameters
fileSpecifies a filename in which to save the generated PostScript output.
xDefines the X coordinate of the upper left corner of the rectangle on the page containing the PostScript output. All coordinates are specified in the world coordinate system, which maps a rectangle defined by the points (0;0) and (2000;2000) to a page.
yDefines the Y coordinate of the upper left corner of the rectangle.
widthDefines the width of the rectangle.
heightDefines the height of the rectangle.
portraitSpecifies the orientation of the PostScript output on the page. If true, a portrait orientation is used, otherwise a landscape orientation is used.
stretchSpecifies whether or not PostScript output should be stretched when mapping it to the specified rectangle:
  • If true, the PostScript output will be stretched to fit the rectangle exactly. This may distort printed objects.
  • If false, the ratio of height to width of the widget will be preserved in the PostScript output. This may leave some parts of the specified rectangle blank.
centerSpecifies whether or not PostScript output should be centered inside the specified output rectangle when stretch=false results in unused space on the sides of the rectangle. If true, the output will be centered inside the output area, otherwise it will be anchored in the upper left corner of the rectangle.
Returns
true if PostScript output was successfully written to the file, otherwise false.

The drawing's hierarchy must be set up in order to generate PostScript output. Use UpdateGlgbefore calling ExportPostScript to make sure the drawing is up to date.

◆ NativePrint()

bool NativePrint ( Graphics  graphics)

Generates printing output of the current state of the viewport's graphics.

If the object is a light viewport, the output will be generated for its parent viewport.

Parameters
graphicsPrint graphics context.
Returns
true on success.

◆ SaveImage()

static bool SaveImage ( Bitmap  image,
String  image_file,
System.Drawing.Imaging.ImageFormat  image_format 
)
static

Saves an image to a file in a requested format.

CreateImage can be used to generates an image of the current state of a viewport's graphics

Parameters
imageImage to save.
image_fileFilename to save the image to.
image_formatImage format to use.
Returns
true on success.