Name | Text |
Button1 | First |
Button2 | Previous |
Button3 | Next |
Button4 | Last |
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.WinForms
[C#]
using Leadtools;
using Leadtools.Codecs;
using Leadtools.WinForms;
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);
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' goto first page
If (RasterImageViewer1.Image.Page <> 1) Then
RasterImageViewer1.Image.Page = 1
UpdateCaption()
End If
End Sub
[C#]
private void button1_Click(object sender, System.EventArgs e)
{
// goto first page
if(rasterImageViewer1.Image.Page != 1)
{
rasterImageViewer1.Image.Page = 1;
UpdateCaption();
}
}
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' goto previous page
If (RasterImageViewer1.Image.Page > 1) Then
RasterImageViewer1.Image.Page = RasterImageViewer1.Image.Page - 1
UpdateCaption()
End If
End Sub
[C#]
private void button2_Click(object sender, System.EventArgs e)
{
// goto previous page
if(rasterImageViewer1.Image.Page > 1)
{
rasterImageViewer1.Image.Page--;
UpdateCaption();
}
}
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' goto next page
If (RasterImageViewer1.Image.Page < RasterImageViewer1.Image.PageCount) Then
RasterImageViewer1.Image.Page = RasterImageViewer1.Image.Page + 1
UpdateCaption()
End If
End Sub
[C#]
private void button3_Click(object sender, System.EventArgs e)
{
// goto next page
if(rasterImageViewer1.Image.Page < rasterImageViewer1.Image.PageCount)
{
rasterImageViewer1.Image.Page++;
UpdateCaption();
}
}
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
' goto last page
If (RasterImageViewer1.Image.Page <> RasterImageViewer1.Image.PageCount) Then
RasterImageViewer1.Image.Page = RasterImageViewer1.Image.PageCount
UpdateCaption()
End If
End Sub
[C#]
private void button4_Click(object sender, System.EventArgs e)
{
// goto last page
if(rasterImageViewer1.Image.Page != rasterImageViewer1.Image.PageCount)
{
rasterImageViewer1.Image.Page = rasterImageViewer1.Image.PageCount;
UpdateCaption();
}
}