public void ReplacePage(
int index,
RasterImage image
)
Public Sub ReplacePage( _
ByVal index As Integer, _
ByVal image As RasterImage _
)
- (void)replacePageAtIndex:(NSInteger)index
withPage:(LTRasterImage *)page
public:
void ReplacePage(
int index,
RasterImage^ image
)
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.
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.
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 LeadtoolsExamples.Common;
using Leadtools.Svg;
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("----------------");
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Controls
Imports Leadtools.Dicom
Imports Leadtools.Drawing
Imports Leadtools.Svg
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
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document