Add an event handler to the Form1 Load event and add the following code:
[Visual Basic]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Intitialize a new RasterCodecs object.
Dim codecs As New RasterCodecs()
' Load OCR1 to OCR4 and add them all to one image
Dim pageFileName() As String = _
{ _
"C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif", _
"C:\Users\Public\Documents\LEADTOOLS Images\Ocr2.tif", _
"C:\Users\Public\Documents\LEADTOOLS Images\Ocr3.tif", _
"C:\Users\Public\Documents\LEADTOOLS Images\Ocr4.tif" _
}
' load all the files in pageFileName as pages into one image
Dim image As RasterImage = Nothing
For i As Integer = 0 To pageFileName.Length - 1
' load the page image
Dim page As RasterImage = codecs.Load(pageFileName(i))
If (i = 0) Then
' first image, just save it into our variable
image = page
Else
' add this page into our image
image.AddPage(page)
' we do not need this page anymore
page.Dispose()
End If
Next
' we can now use this image in our viewer. But let us try saving into a multi-page file then reloading it
Dim outputFileName As String = "C:\Users\Public\Documents\LEADTOOLS Images\Ocr_All.tif"
' we can now just put "image" into the viewer, but lets save it as multi-page tiff and reload it
codecs.Save(image, outputFileName, RasterImageFormat.Tif, 1, 1, 4, 1, CodecsSavePageMode.Overwrite)
image.Dispose()
' load this file into a new image and put in the viewer.
' we know we have four pages, but let us use the GetInformation pages to get the number of pages
Dim info As CodecsImageInfo = codecs.GetInformation(outputFileName, True)
image = codecs.Load(outputFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, info.TotalPages)
' setup the viewer into Fit mode
RasterImageViewer1.SizeMode = RasterPaintSizeMode.Fit
' view this image
RasterImageViewer1.Image = image
UpdateCaption()
End Sub
Private Sub UpdateCaption()
Text = String.Format("Page {0} of {1}", RasterImageViewer1.Image.Page, RasterImageViewer1.Image.PageCount)
End Sub
[C#]
private void Form1_Load(object sender, System.EventArgs e)
{
// Intitialize a new RasterCodecs object.
RasterCodecs codecs = new RasterCodecs();
// Load OCR1 to OCR4 and add them all to one image
string[] pageFileName =
{
@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr1.tif",
@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr2.tif",
@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr3.tif",
@"C:\Users\Public\Documents\LEADTOOLS Images\Ocr4.tif"
};
// load all the files in pageFileName as pages into one image
RasterImage image = null;
for(int i = 0; i < pageFileName.Length; i++)
{
// load the page image
RasterImage page = codecs.Load(pageFileName[i]);
if(i == 0)
{
// first image, just save it into our variable
image = page;
}
else
{
// add this page into our image
image.AddPage(page);
// we do not need this page anymore
page.Dispose();
}
}
// we can now use this image in our viewer. But let us try saving into a multi-page file then reloading it
string outputFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\Ocr_All.tif";
// we can now just put "image" into the viewer, but lets save it as multi-page tiff and reload it
codecs.Save(image, outputFileName, RasterImageFormat.Tif, 1, 1, 4, 1, CodecsSavePageMode.Overwrite);
image.Dispose();
// load this file into a new image and put in the viewer.
// we know we have four pages, but let us use the GetInformation pages to get the number of pages
CodecsImageInfo info = codecs.GetInformation(outputFileName, true);
image = codecs.Load(outputFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, info.TotalPages);
// setup the viewer into Fit mode
rasterImageViewer1.SizeMode = RasterPaintSizeMode.Fit;
// view this image
rasterImageViewer1.Image = image;
UpdateCaption();
}
private void UpdateCaption()
{
Text = string.Format("Page {0} of {1}", rasterImageViewer1.Image.Page, rasterImageViewer1.Image.PageCount);
}