LEADTOOLS (Leadtools assembly)

ReplacePage Method

Show in webframe
Example 







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.
The source image to replace with.
Replaces an existing page in this RasterImage.
Syntax
public void ReplacePage( 
   int index,
   RasterImage image
)
'Declaration
 
Public Sub ReplacePage( _
   ByVal index As Integer, _
   ByVal image As RasterImage _
) 
'Usage
 
Dim instance As RasterImage
Dim index As Integer
Dim image As RasterImage
 
instance.ReplacePage(index, image)
public void ReplacePage( 
   int index,
   RasterImage image
)
-(void)replacePage:(int)index 
             image:(LTRasterImage*)image;
            
public void replacePage(
  int index, 
  RasterImage image
)
            
 function Leadtools.RasterImage.ReplacePage( 
   index ,
   image 
)
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.
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
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.WinForms
Imports Leadtools.Dicom
Imports Leadtools.Drawing

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
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.WinForms;
using Leadtools.Dicom;
using Leadtools.Drawing;

      
public void TestReplacePage()
{
   // Create a mult-page image from the following files:
   string[] pageFileNames =
   {
      Path.Combine(ImagesPath.Path,"Sample1.cmp"),
      Path.Combine(ImagesPath.Path,"Sample2.cmp"),
      Path.Combine(ImagesPath.Path,"Sample3.cmp"),
      Path.Combine(ImagesPath.Path,"Sample4.cmp")
   };
   string newPageFileName = Path.Combine(ImagesPath.Path,"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("----------------");
}
RasterImageExamples.prototype.TestReplacePage = function ( )
{
   Tools.SetLicense ( ) ;
   with ( Leadtools ) {
      with ( Leadtools.Codecs ) {
         // Create a mult-page image from the following files:
         var pageFileNames =
         [
            "Assets\\Sample1.cmp",
            "Assets\\Sample2.cmp",
            "Assets\\Sample3.cmp",
            "Assets\\Sample4.cmp",
         ];
      
         var newPageFileName = "Assets\\Image1.cmp";

         var codecs = new RasterCodecs();

         var image = null;
      
         var promises = pageFileNames.map(function (pageFileName) {

            return Tools.AppInstallFolder().getFileAsync(pageFileName).then (function ( loadFile) {
               return codecs.loadAsync(LeadStreamFactory.create(loadFile), 0, CodecsLoadByteOrder.bgrOrGray, 1, 1)})
            .then ( function ( page ) {

               if (image != null)
               {
                  image.addPage(page);
               }
               else
               {
                  image = page;
               }
            });
         });
         
         return WinJS.Promise.join ( promises ).then( function ( ) {

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

            // Load the page to replace
            return Tools.AppInstallFolder().getFileAsync(newPageFileName)})
            .then ( function ( loadFile2 ) {
               return codecs.loadAsync(LeadStreamFactory.create(loadFile2), 0, CodecsLoadByteOrder.bgrOrGray, 1, 1)})
            .then ( function (newPage ) {
               console.info("Loaded a new page of size " + newPage.width +" by " + 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.close();
               codecs.close();
            });
      }
   }
}

function ShowMultiPageImageInfo(message, image) {
   console.info(message);

   var savePage = image.page;

   for (var i = 1; i <= image.pageCount; i++) {
      image.page = i;
      console.info("  " + i + ": Size " + image.width + " by " + image.height + " pixels");
   }

   image.page = savePage;

   console.info("----------------");
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;

      
public async Task TestReplacePage()
{
   // Create a mult-page image from the following files:
   string[] pageFileNames =
   {
      @"Assets\Sample1.cmp",
      @"Assets\Sample2.cmp",
      @"Assets\Sample3.cmp",
      @"Assets\Sample4.cmp",
   };
   string newPageFileName = @"Assets\Image1.cmp";

   RasterCodecs codecs = new RasterCodecs();

   RasterImage image = null;
   foreach (string pageFileName in pageFileNames)
   {
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(pageFileName);
      RasterImage page = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 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
   StorageFile loadFile2 = await Tools.AppInstallFolder.GetFileAsync(newPageFileName);
   RasterImage newPage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile2), 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);

   Debug.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)
{
   Debug.WriteLine(message);

   int savePage = image.Page;

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

   image.Page = savePage;

   Debug.WriteLine("----------------");
}
Requirements

Target Platforms

See Also

Reference

RasterImage Class
RasterImage Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.