Images

DynamicPDF Core Suite for .NET supports 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.

Image Page Element and Background Image Page Element

Images are added to a page using the Image Page Element or the Background Image Page Element. The following code illustrates.

// 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 ) );        
' 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 ) )      

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.

// Adds an image to a page.
page.Elements.Add( new Image( @"C:\MyLogo.gif", 0, 0 ) );        
' Adds an image to a page.
MyPage.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.

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

Adding Images From A System.Drawing.Bitmap Object

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

// Adds an image to a page.
page.Elements.Add( new Image( bitmap, 0, 0 ) );        
' Adds an image to a page.
MyPage.Elements.Add( New Image( MyBitmap, 0, 0 ) )  

Adding Images From A Byte Array

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

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

Adding Images From A Database Field

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

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

In This Section

Refer to the following topics for more information on Images.

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.

In this topic