LEADTOOLS (Leadtools assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
ReplacePage Method
See Also 
Leadtools Namespace > RasterImage Class : ReplacePage Method



index
The 1-based index of the page from image to replace. If index is equal to -1, the last page in the image will be replaced.
image
The source image to replace with.
index
The 1-based index of the page from image to replace. If index is equal to -1, the last page in the image will be replaced.
image
The source image to replace with.
Replaces an existing page in this RasterImage. Supported in Silverlight, Windows Phone 7

Syntax

Visual Basic (Declaration) 
Public Sub ReplacePage( _
   ByVal index As Integer, _
   ByVal image As RasterImage _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterImage
Dim index As Integer
Dim image As RasterImage
 
instance.ReplacePage(index, image)
C# 
public void ReplacePage( 
   int index,
   RasterImage image
)
C++/CLI 
public:
void ReplacePage( 
   int index,
   RasterImage^ image
) 

Parameters

index
The 1-based index of the page from image to replace. If index is equal to -1, the last page in the image will be replaced.
image
The source image to replace with.

Example

Visual BasicCopy Code
Public Sub TestReplacePage()
      ' Create a mult-page image from the following files:

      Dim pageFileNames() As String = _
      { _
         Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Sample2.cmp"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Sample3.cmp"), _
         Path.Combine(LEAD_VARS.ImagesDir, "Sample4.cmp") _
      }

      Dim newPageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")

      Dim codecs As New RasterCodecs()

      Dim image As RasterImage = Nothing
      For Each pageFileName As String In pageFileNames
         Dim page As RasterImage = codecs.Load(pageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)

         If Not IsNothing(image) Then
            image.AddPage(page)
         Else
            image = page
         End If
      Next

      ' Show the image now
      ShowMultiPageImageInfo("Original image", image)

      ' Load the page to replace
      Dim newPage As RasterImage = codecs.Load(newPageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)

      Console.WriteLine("Loaded a new page of size {0} by {1}", newPage.Width, newPage.Height)

      ' Replace the second page on the image with this page
      image.ReplacePage(2, newPage)

      ' Show the list now
      ShowMultiPageImageInfo("New image after replacing page number 2", image)

      image.Dispose()
      codecs.Dispose()
   End Sub

   Private Shared Sub ShowMultiPageImageInfo(ByVal message As String, ByVal image As RasterImage)
      Console.WriteLine(message)

      Dim savePage As Integer = image.Page

      For i As Integer = 1 To image.PageCount
         image.Page = i
         Console.WriteLine("  {0}: Size {1} by {2} pixels", i, image.Width, image.Height)
      Next

      image.Page = savePage

      Console.WriteLine("----------------")
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
C#Copy Code
public void TestReplacePage()
   {
      // Create a mult-page image from the following files:

      string[] pageFileNames =
      {
         Path.Combine(LEAD_VARS.ImagesDir,"Sample1.cmp"),
         Path.Combine(LEAD_VARS.ImagesDir,"Sample2.cmp"),
         Path.Combine(LEAD_VARS.ImagesDir,"Sample3.cmp"),
         Path.Combine(LEAD_VARS.ImagesDir,"Sample4.cmp")
      };
      string newPageFileName = Path.Combine(LEAD_VARS.ImagesDir,"Image1.cmp");

      RasterCodecs codecs = new RasterCodecs();

      RasterImage image = null;
      foreach(string pageFileName in pageFileNames)
      {
         RasterImage page = codecs.Load(pageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

         if(image != null)
         {
            image.AddPage(page);
         }
         else
         {
            image = page;
         }
      }

      // Show the image now
      ShowMultiPageImageInfo("Original image", image);

      // Load the page to replace
      RasterImage newPage = codecs.Load(newPageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

      Console.WriteLine("Loaded a new page of size {0} by {1}", newPage.Width, newPage.Height);

      // Replace the second page on the image with this page
      image.ReplacePage(2, newPage);

      // Show the list now
      ShowMultiPageImageInfo("New image after replacing page number 2", image);

      image.Dispose();
      codecs.Dispose();
   }

   private static void ShowMultiPageImageInfo(string message, RasterImage image)
   {
      Console.WriteLine(message);

      int savePage = image.Page;

      for(int i = 1; i <= image.PageCount; i++)
      {
         image.Page = i;
         Console.WriteLine("  {0}: Size {1} by {2} pixels", i, image.Width, image.Height);
      }

      image.Page = savePage;

      Console.WriteLine("----------------");
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
SilverlightCSharpCopy Code
SilverlightVBCopy Code

Remarks

This method pulls the current active page of image and inserts into the current RasterImage object at page number = index. The number of pages in image is decremented by one, if image had only one page prior to calling this method, then the image object is disposed of and should not be used afterwards.

The RasterImage object can hold multiple pages with different sizes. The AddPage, AddPages, InsertPage and InsertPages methods allows adding new pages to an existing RasterImage.

The RemovePageAt, RemovePages and RemoveAllPages methods allows removing existing pages from a RasterImage object.

The ReplacePage and ReplacePages methods allows replace existing pages in a RasterImage object.

The PageCount property holds the total number of pages in a RasterImage object while the Page property allows you to change the current active page.

The current active page (The page indicated by the Page property) is used by default when accessing the data of a RasterImage object unless otherwise indicated.

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only), Windows Phone 7

See Also