02-21-2008, 10:26
|
danny_live
Joined on 02-21-2008
Posts 4
|
Load a batch of multiple page tiff files
|
 
 
|
|
|
I have two codes to load a tiff files to the thumbnail browser.
1) Using a FolderBrowserDialog
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.Description = "Select the directory that contains the images you want.";
dlg.ShowNewFolderButton = false;
dlg.SelectedPath = @"C:\Documents and Settings\admin\Desktop\tiffFileFldr";
if (dlg.ShowDialog(this) == DialogResult.OK)
{
try
{
if (Thumbnail.IsLoadingThumbnails)
Thumbnail.CancelLoadingThumbnails();
Thumbnail.Items.Clear();
Thumbnail.LoadThumbnails(dlg.SelectedPath, "*.*", RasterThumbnailBrowserLoadFlags.None);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
updateMyControls();
}
}
Here all files that are in the folder get into the thumbnail. but only the first page of the files are displayed. I need all the pages to be displayed followed by the next file's pages.
2) Using OpenFileDialog
private void singleFileToolStripMenuItem_Click(object sender, EventArgs e)
{
string file_name = string.Empty;
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Tagged File Formats (*.tif, *.tiff) Files|*.tif;*.tiff";
Thumbnail.Items.Clear();
if (dlg.ShowDialog(this) == DialogResult.OK)
{
file_name = dlg.FileName;
}
RasterCodecs codecs = new RasterCodecs();
codecs.LoadPage += Page_Load;
RasterImage rstImg = codecs.Load(file_name);
dlg.Dispose();
}
private void Page_Load(object sender, Leadtools.Codecs.CodecsPageEventArgs e)
{
if (e.State == CodecsPageEventState.After)
{
RasterImageListItem item = new RasterImageListItem(e.Image, e.Page, "Item" + e.Page.ToString());
Thumbnail.Items.Add(item);
Application.DoEvents();
}
}
Here I am using OpenFileDialog so as to open a file having multiple pages. All pages are displayed but when I select any thumbnail page only the first page is displayed. More ever the progressive time taken is very slow.
Below is the code of thumnail selected index changed code for both the cases
private void Thumbnail_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
RasterImageListItemCollection selectedItems = Thumbnail.SelectedItems;
if (selectedItems.Count > 0)
{
RasterImageListItem item = selectedItems[0];
if (item.FileName == null)
{
Thumbnail.Codecs.Save(Thumbnail.Items[item.Page].Image, "c:\\temptest.tif", RasterImageFormat.Tif, 24);
ImgViewer.Image = item.Image; // item.Image;
}
if (item.FileName != _currentFileName)
{
_currentFileName = item.FileName;
ImgViewer.Image = Thumbnail.Codecs.Load(
_currentFileName,
0,
CodecsLoadByteOrder.BgrOrGray,
item.Page,
item.Page);
}
}
else
{
ImgViewer.Image = null;
_currentFileName = null;
}
}
catch
{
ImgViewer.Image = null;
}
finally
{
//_lblViewer.Invalidate();
updateMyControls();
}
}
|
|
|
|
|
Report
|
|
|
|