BackgroundImage Class | Image Class | ImageData Class | Image Reuse | Programming with Generator for .NET

Language

Visual Basic

C#

Show All

DynamicPDF™ Generator for .NET has support for 9 image types and transparent images. It can read images from a file, System.IO.Stream object, or System.Drawing.Bitmap object. This section explains how to use images in a document.

Images can be added to a page using the Image Page Element or the Background Image Page Element:

[Visual Basic]
' Adds a background image and image to a page.
MyPage.Elements.Add( New BackgroundImage( "C:\MyBackground.gif" ) )
MyPage.Elements.Add( New Image( "C:\MyLogo.gif", 0, 0 ) )
[C#]
// Adds a background image and image to a page.
page.Elements.Add( new BackgroundImage( @"C:\MyBackground.gif" ) );
page.Elements.Add( new Image( @"C:\MyLogo.gif", 0, 0 ) );

NOTE: The examples in this topic show how to add an image when it is not going to be reused multiple times. For details on how to most efficiently handle images that will be used multiple times, see the Image Reuse topic.

Adding Images From A File

Images can be created from a file as follows:

[Visual Basic]
' Adds an image to a page.
MyPage.Elements.Add( New Image( "C:\MyLogo.gif", 0, 0 ) )
[C#]
// Adds an image to a page.
page.Elements.Add( new Image( @"C:\MyLogo.gif", 0, 0 ) );

Adding Images From A System.IO.Stream Object

Images can be created from a System.IO.Stream object as follows:

[Visual Basic]
' Adds an image to a page.
MyPage.Elements.Add( New Image( ImageData.GetImage( MyStream ), 0, 0 ) )
[C#]
// Adds an image to a page.
page.Elements.Add( new Image( ImageData.GetImage( stream ), 0, 0 ) );

Adding Images From A System.Drawing.Bitmap Object

Images can be created from a System.Drawing.Bitmap object as follows:

[Visual Basic]
' Adds an image to a page.
MyPage.Elements.Add( New Image( MyBitmap, 0, 0 ) )
[C#]
// Adds an image to a page.
page.Elements.Add( new Image( bitmap, 0, 0 ) );

Adding Images From A Byte Array

Images can be created from a database field or byte array as follows:

[Visual Basic]
' Adds an image from a byte array to a page.
MyPage.Elements.Add( New Image( ImageData.GetImage( MyByteArray ), 0, 0 ) )
[C#]
// Adds an image from a byte array to a page.
page.Elements.Add( new Image( ImageData.GetImage( byteArray ), 0, 0 ) );

Adding Images From A Database Field

Images can be created from a database field or byte array as follows:

[Visual Basic]
' The "MyDataReader" variable is a DataReader object.
MyPage.Elements.Add( New Image( ImageData.GetImage( CType( MyDataReader("ImageField"), Byte() ) ), 0, 0 ) )
[C#]
// The "dataReader" variable is a DataReader object.
page.Elements.Add( new Image( ImageData.GetImage( (byte[])dataReader["ImageField"] ), 0, 0 ) );

In This Section

Image Formats
Lists and Explains the different image formats that are supported.
Image Resolution
Explains how to set and adjust the resolution and size of images.
Tiff Images
Explains the different options for Tiff images that are supported.
Image Reuse
Explains how to most efficiently use reuse images.

See Also 

BackgroundImage Class | Image Class | ImageData Class | Image Reuse | Programming with Generator for .NET