←Select platform

RemovePages Method

Summary
Removes one or more pages from this RasterImage.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void RemovePages( 
   int startIndex, 
   int count 
) 
- (void)removePages:(NSInteger)start count:(NSInteger)count 
public void removePages(int startIndex, int count) 
public: 
void RemovePages(  
   int startIndex, 
   int count 
)  
def RemovePages(self,startIndex,count): 

Parameters

startIndex
1-based index of the first page to remove.

count
Number of pages to remove. Specify -1 to remove all pages.

Remarks

You cannot have a RasterImage with no pages, therefore, an exception will occur if you attempt to remove the only page left in a RasterImage object

This method pulls the pages from  startIndex to  startIndex +  count and appends it at the end of the pages list of this RasterImage object. The number of pages in this image is decremented by  count.

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#
Java
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 PagesExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.Options.Load.AllPages = true; 
 
   string srcFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "eye.gif"); 
   string srcFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "image1.cmp"); 
 
   // Load the multi-page image 
   RasterImage srcImage = codecs.Load(srcFileName1); 
 
   // Show the number of pages in this file 
   Console.WriteLine("Pages in the image: {0}", srcImage.PageCount); 
 
   // Show and change the active page 
   Console.WriteLine("Active page: {0}", srcImage.Page); 
   srcImage.Page = 3; 
   Console.WriteLine("Active page: {0}", srcImage.Page); 
   srcImage.Page = 1; 
 
   // Load a single page image and add it to the end 
   RasterImage pageImage = codecs.Load(srcFileName2); 
   Console.WriteLine("Adding a single page"); 
   srcImage.AddPage(pageImage); 
   Console.WriteLine("Pages in the image: {0}", srcImage.PageCount); 
 
   // Load a multi page image and add a few pages to this image 
   pageImage = codecs.Load(srcFileName1); 
   Console.WriteLine("Adding multi-pages"); 
   srcImage.AddPages(pageImage, 1, 2); 
   Console.WriteLine("Pages in the image: {0}", srcImage.PageCount); 
 
   // Insert a page in the middle 
   Console.WriteLine("Inserting a page"); 
   srcImage.InsertPage(4, pageImage); 
   Console.WriteLine("Pages in the image: {0}", srcImage.PageCount); 
 
   // Insert the rest of the pages at the beginning 
   Console.WriteLine("Inserting pages"); 
   srcImage.InsertPages(0, pageImage, 1, -1); 
   Console.WriteLine("Pages in the image: {0}", srcImage.PageCount); 
 
   // Remove the first page 
   Console.WriteLine("Removing a page"); 
   srcImage.RemovePageAt(1); 
   Console.WriteLine("Pages in the image: {0}", srcImage.PageCount); 
 
   // Remove the last 3 pages 
   Console.WriteLine("Removing pages"); 
   srcImage.RemovePages(srcImage.PageCount - 3, -1); 
   Console.WriteLine("Pages in the image: {0}", srcImage.PageCount); 
 
   // Remove all the pages (leaves 1) 
   Console.WriteLine("Removing all pages"); 
   srcImage.RemoveAllPages(); 
   Console.WriteLine("Pages in the image: {0}", srcImage.PageCount); 
 
   srcImage.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.ArrayList; 
import java.util.List; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.core.*; 
import leadtools.svg.*; 
import leadtools.imageprocessing.CloneCommand; 
import leadtools.imageprocessing.FillCommand; 
import leadtools.imageprocessing.FlipCommand; 
import leadtools.imageprocessing.GrayscaleCommand; 
import leadtools.imageprocessing.color.InvertCommand; 
import leadtools.imageprocessing.color.PosterizeCommand; 
 
 
public void pagesExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.getOptions().getLoad().setAllPages(true); 
   String srcFileName1 = combine(LEAD_VARS_IMAGES_DIR, "eye.gif"); 
   String srcFileName2 = combine(LEAD_VARS_IMAGES_DIR, "image1.cmp"); 
 
   // Load the multi-page image 
   RasterImage srcImage = codecs.load(srcFileName1); 
 
   // Show the number of pages in this file 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
 
   // Show and change the active page 
   System.out.printf("Active page: %s%n", srcImage.getPage()); 
   srcImage.setPage(1); 
   System.out.printf("Active page: %s%n", srcImage.getPage()); 
 
   // Load a single page image and add it to the end 
   RasterImage pageImage = codecs.load(srcFileName2); 
   System.out.println("Adding a single page"); 
   srcImage.addPage(pageImage); 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
 
   // Load a multi page image and add a few pages to this image 
   pageImage = codecs.load(srcFileName1); 
   System.out.println("Adding multi-pages"); 
   srcImage.addPages(pageImage, 1, 1); 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
 
   // Insert a page in the middle 
   pageImage = codecs.load(srcFileName2); 
   System.out.println("Inserting a page"); 
   srcImage.insertPage(3, pageImage); 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
 
   // Insert the rest of the pages at the beginning 
   System.out.println("Inserting pages"); 
   srcImage.insertPages(0, pageImage, 1, -1); 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
 
   // Remove the first page 
   System.out.println("Removing a page"); 
   srcImage.removePageAt(1); 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
 
   // Remove the last 3 pages 
   System.out.print("Removing pages"); 
   srcImage.removePages(srcImage.getPageCount() - 1, 2); 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
 
   // Remove all the pages (leaves 1) 
   pageImage = codecs.load(srcFileName2); 
   System.out.println("Adding a single page"); 
   srcImage.addPage(pageImage); 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
   System.out.println("Removing all pages"); 
   srcImage.removeAllPages(); 
   System.out.printf("Pages in the image: %s%n", srcImage.getPageCount()); 
   assertTrue("Not all extra pages were removed", srcImage.getPageCount() == 1); 
 
   srcImage.dispose(); 
   codecs.dispose(); 
} 
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.