Welcome to LEAD Support Forum Login | Register | Faq  

    LEAD Support Forum
  Resource to find answers and post technical questions about LEAD products.
Search    
   

Re: Load a tiff file from an http site
Started by danny_live at 02-21-2008 10:26. Topic has 4 replies.

Print Search « Previous Thread Next Thread »
  02-21-2008, 10:26
danny_live is not online. Last active: 2/25/2008 6:12:20 AM danny_live

Not Ranked
Joined on 02-21-2008
Posts 4
Load a batch of multiple page tiff files
Reply Quote
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 
  02-21-2008, 16:23
GregR is not online. Last active: 11/17/2008 11:10:19 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,705
Re: Load a batch of multiple page tiff files
Reply Quote
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

Greg Ross
LEADTOOLS Technical Support
   Report 
  02-22-2008, 2:00
danny_live is not online. Last active: 2/25/2008 6:12:20 AM danny_live

Not Ranked
Joined on 02-21-2008
Posts 4
Re: Load a batch of multiple page tiff files
Reply Quote
Thank you Greg
   Report 
  02-22-2008, 2:23
danny_live is not online. Last active: 2/25/2008 6:12:20 AM danny_live

Not Ranked
Joined on 02-21-2008
Posts 4
Re: Load a tiff file from an http site
Reply Quote
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
   Report 
  02-22-2008, 10:31
GregR is not online. Last active: 11/17/2008 11:10:19 AM GregR



Top 10 Posts
Joined on 05-31-2006
In House
Posts 1,705
Re: Load a tiff file from an http site
Reply Quote
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(); 
}


Greg Ross
LEADTOOLS Technical Support
   Report 
Post
LEAD Support Fo... » General » Feature Request... » Re: Load a tiff file from an http site

Powered by Community Server, by Telligent Systems