←Select platform

ReplacePage Method

Summary
Replaces an existing page in this RasterImage.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void ReplacePage( 
   int index, 
   RasterImage image 
) 
- (void)replacePageAtIndex:(NSInteger)index  
                  withPage:(LTRasterImage *)page 
public void replacePage( 
   int index, 
   RasterImage image 
); 
public: 
void ReplacePage(  
   int index, 
   RasterImage^ image 
)  
def ReplacePage(self,index,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.

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.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using Leadtools.Svg; 
 
 
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:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.5.22
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.