FaxMan Jr
Viewing Faxes
The .NET Framework has support for viewing tiff files.  It is relatively intolerant code though. If it runs into an error on one line it will fail to display the rest of the page painting it solid instead.  The fax files we receive are written straight to file as received from the modem.  This presents a problem with the .NET framework.  One solution is to simply import the file using the ImportFiles method of the Faxing object.  This works in most cases.

Another option for viewing files is the ImageMan.NET components, this obviates the need to import the received files.  It also provides a host of useful features which improve user experience. The ImageMan.NET has exceptional viewing code for viewing black and white code this feature is called antialiasing. It also allows you to view the image at it's native bit depth(black and white) instead of having to inflate it to 32 times it's original size in memory as the framework does in order to display it with GDI+.  In addition to better scaling and viewing there is a thumbnail control for viewing all the pages in a received fax, image preview dialogs for loading faxes, and rotation as well as deskew for faxes that come in upside down or did not feed correctly.  ImageMan.NET also has full support for working with memory streams as well, so you can write your faxes to a database and read them without having to write them to disk.

.NET Framework code to load all the pages of a fax into an array for displaying each page one at a time.

using System.Drawing;

// Form level variable
private ArrayList imgs

private ArrayList LoadFaxFile(String fileName)
{
   ArrayList imgs = new ArrayList();

   // load image into bitmap ArrayList
   // Sets the tiff file as an image object.
   System.Drawing.Image objImage = Image.FromFile(fileName);
   Guid objGuid = objImage.FrameDimensionsList[0];
   System.Drawing.Imaging.FrameDimension objDimension = new System.Drawing.Imaging.FrameDimension(objGuid);

   // Gets the total number of frames in the .tiff file
   int totFrame = objImage.GetFrameCount(objDimension);

   // Saves every frame as a seperate image in the ArrayList
   int i;
   for (i = 0; i < totFrame; i ++)
   {
       objImage.SelectActiveFrame(objDimension, i);
       Image img  = (System.Drawing.Image)objImage.Clone();
       imgs.Add(img);
   }

   return(imgs);
}

In the Main FaxMan Jr .NET samples we demonstrate using the Framework to display the image.  We have put a panel on the form and set it's AutoScroll property to true;

private System.Windows.Forms.Panel pnViewFax;
pnViewFax.AutoScroll = true;

We use this panel to host the PictureBox control, by dropping the PictureBox on to the panel in the forms designer.

this.pnViewFax.Controls.Add(this.pictureBox1);

This is the code to load the image from the array into the picture box. Note that once the picture is loaded the picture box is much bigger than the form. Since the panel has AutoScroll set to true scroll bars appear after we load the image allowing us to scroll around the image.

private void LoadImage() { LoadImage(0); }
private void LoadImage(int page)
{
   if ( (null != imgs) && (imgs.Count > page) )
   {
       pictureBox1.Image = (System.Drawing.Image)imgs[page];
       pictureBox1.Width = pictureBox1.Image.Width;
       pictureBox1.Height = pictureBox1.Image.Height;
       pictureBox1.Refresh();
   }
}

private void OpenFaxFile(String faxFile)
{
   if (faxFile.Length > 1)
   {
       imgs =  LoadFaxFile(faxFile);
       LoadImage();
   }

}

Finally we want to be able to page through the image so we have added some menu handlers.

// Form Level Variable
private int _page;

private void mnuPageFirst_Click(object sender, System.EventArgs e)
{
   LoadImage(_page = 0);
}

private void mnuPagePrevious_Click(object sender, System.EventArgs e)
{
   if (_page > 0) LoadImage(--_page);
}

private void mnuPageNext_Click(object sender, System.EventArgs e)
{
   if (imgs.Count - 1 > _page) LoadImage(++_page);
}

private void mnuPageLast_Click(object sender, System.EventArgs e)
{
   if (imgs.Count - 1 > _page) LoadImage(_page = imgs.Count - 1);
}


The ImageMan .NET controls already have a concept of an image collection. Making it even easier to work with the images individually or as a group - scaling to fit the window or the width of the window, rotating, rubber band zoom, panning, page scrolling that responds to the mouse wheel, saving, printing and more.

 

 


© 2014 Data Techniques, Inc. All Rights Reserved.

Send comments on this topic.