Opening Image Speed

obrien.james

Member
Joined
Sep 11, 2009
Messages
15
Programming Experience
Beginner
Hi,

Im trying to make a win form that opens multipage tiff files. The code that im currently using is loading the image into a Image Variable (BaseImg) with the following line of code:

BaseImg = Image.FromFile("Some path").

Then i iterate throught the baseimg and create a bitmap of each page to be stored in a variable Frames which is a ListOf(Image).

Finally I load Frames(0) into a picture box control which is inside a panel.

I have a small multipage tiff file with 5 pages and it takes some time to open ~ 5-8 seconds. This may not seem like a long time but at work we use a program that loads multipage tiff files and it opens instantly.

Then when I change the image within the form just by setting Picturebox1.image = Frmaes(currentimage+1). This can take some time even though the image is stored in a variable. Again at work the program changes page in an instant.

What i'm asking is there any way by which I can speed the opening of the images or if there is a better way to store my split tiff images.

James
 
You don't need to do all that, once the tif is loaded into Image object all frames are available to display right away with no processing or additional load time, you can just use Image.SelectActiveFrame method and refresh the PictureBox. Let's say you have a NumericUpDown (minimum=1) and a PictureBox, when loading:
VB.NET:
Me.PictureBox1.Image = Image.FromFile("multipage.tif")
Me.PageNUD.Value = 1
Me.PageNUD.Maximum = Me.PictureBox1.Image.GetFrameCount(Imaging.FrameDimension.Page)
NumericUpDown ValueChanged event handler:
VB.NET:
If Me.PictureBox1.Image Is Nothing Then Return
Me.PictureBox1.Image.SelectActiveFrame(Imaging.FrameDimension.Page, CInt(Me.PageNUD.Value - 1))
Me.PictureBox1.Refresh()
 
Thanks for that, if I'm using this method what would be the best way to zoom in and out of the image??

As the app will be dealing with scanned images they can be quite big so I want to be able zoom to width etc where I can supply the visible width of the screen and the zoom to make the image fit that size.

Currently I'm using code that creates a new bitmap the size I need then drawing the the current image to the size of the new bitmap.

Ideally I would like to be able to apply the zoom to all pages at once so that when I can page the zoom state will follow.

James
 
Zoom is one of the PictureBox.SizeMode property options. You can combine it with putting the PictureBox in a Panel (with AutoScroll=True) and resizing the Picturebox.
 
Back
Top