Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, February 21, 2008 5:21:11 AM(UTC)
danny_live

Groups: Registered
Posts: 4


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();
}
}
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Thursday, February 21, 2008 11:18:30 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


The RasterThumnailBrowser (or RasterImageList which it inherits) do not natively load multipage images into separate RasterImageListItems.  Each RasterImageListItem contains a RasterImage, so with what you're doing, you likely have a RasterImage object with multiple pages in EACH RasterImageListItem. 

As for the second way you are doing this, you are close.  However, the RasterCodecs.LoadPage event's FormClosingEventArgs' (we'll call it "e" from now on) Image property is the RasterImage that it is building.  In other words, e.Image is what will eventually get returned by RasterCodecs.Load, and with each time the event fires to update the image, e.Image.PageCount is getting larger. 

The RasterImage.Page property affects which page in the multipage RasterImage object is displayed.  However, when you load it to the viewer, you must be loading either all of the pages or just the first one if it's displaying it.

This is likely a slow process because of loading entire multipage images and haveing multiple copies of them in each RasterImageListItem. 

If you want to load and display the individual pages of multipage images in the RasterImageList, you need to check the number of pages in the file, then loop and load each page individually into separate RasterImage objects.  For the best memory use, you should load the stamp of an image if possible, and if not, resize the image to a thumbnail size and then load that individual page whenever you select the corresponding RasterImageListItem.  Here's a demo that might be helpful to you:

http://support.leadtools.com/SupportPortal/cs/forums/17782/ShowPost.aspx
 
#3 Posted : Thursday, February 21, 2008 8:55:35 PM(UTC)
danny_live

Groups: Registered
Posts: 4


Thank you Greg
 
#4 Posted : Thursday, February 21, 2008 9:18:02 PM(UTC)
danny_live

Groups: Registered
Posts: 4


One more thing .

I want to open a tiff file from an http site.

I tried the code

RasterCodecs codecs = new RasterCodecs();

string file_name = @"http://mysite.com/GeneratedTiffFiles/Sample_52.tif";

RasterImage rstImg = codecs.Load(file_name);

But it gives the error "File Not Found"

Anything I need to do?

Thank You
 
#5 Posted : Friday, February 22, 2008 5:26:44 AM(UTC)

GregR  
GregR

Groups: Registered, Tech Support, Administrators
Posts: 764


Use the RasterCodecs.Load overload that takes a System.Uri object.  Here's the example from the help file:

public void LoadUri1Example() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   Uri uri = new Uri(@"http://www.leadtools.com/images/15-homepg-banner.jpg"); 
   RasterImage image = codecs.Load(uri); 
 
   // Show information about tha image 
   Console.WriteLine("Size: {0} by {1} pixels", image.Width, image.Height); 
   Console.WriteLine("Bits/Pixel: {0}", image.BitsPerPixel); 
   image.Dispose(); 
 
   // Clean up 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}
 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.103 seconds.