Victor Image Processing Library How-to Tips

Tiff Page View

The Victor Library gives the web .ASPX developer and the desktop .Net developer the advantages of speed, small size, and ease of use when creating an application to modify or analyze images.

For a developer using the Victor Library it is easy to load any page from a tiff file and display it in the user's browser.

To load and display a tiff page a typical sequence is:

In this example we load a tiff file into a byte array and when a new page or size is requested it is loaded into the image buffer and the image is displayed.

For an introduction to creating online applications using the Victor Library see the application note Creating an ASP.NET Online Image Processing Application

Currently displaying: http://catenarysystems.com/demos/images/leaves.tif
Page: 0
Dimensions: 275 x 310 8-bit
Total pages in tiff file:5

Page: 0 - 4 Zoom:


Upload tiff file from your desktop

Enter URL of tiff file



C Sharp ASP.NET Source Code | Viewimage Source Code | Entire App Source Code


Tiff Page View - the ASPX C# Source Code

Requires Victor Image Processing Library 6 or higher, commercial release or eval copy.
		
// The tiff file is in a byte array in memory and we will load each page as requested		
unsafe int loadtiffdata(byte *bd, imgdes *timage, int pageindex, int magnification){
int rcode;
TiffData tinfo;
int tpages;
int lpage;
imgdes tempimage;

rcode = tiffgetpageinfofrombuffer(bd, &tpages, (int *)0, (int)0);  // Determine total pages in the file		
if(rcode == NO_ERROR){
   rcode = tiffinfopagebyindexfrombuffer(bd, &tinfo, pageindex);  // Get the image dimensions for the page of interest
   if(rcode == NO_ERROR) {
      rcode = allocimage(timage, tinfo.width, tinfo.length, tinfo.vbitcount);// Allocate space for the image in memory
         if(rcode == NO_ERROR) {
         rcode = loadtifpagebyindexfrombuffer(bd, timage, pageindex);// Load the image from the tiff file into the image buffer
            if(rcode == NO_ERROR || rcode == BAD_DATA) {
               if(tinfo.vbitcount == 16){       // Replace 16-bit grayscale image with 8-bit grayscale
                  rcode = allocimage(&tempimage, tinfo.width, tinfo.length, 8);
                  rcode = convertgray16to8(timage, &tempimage);
                  if(rcode == NO_ERROR) {
                     freeimage(timage);
                     copyimgdes(&tempimage, timage);
                  }
               }
               if(magnification != 100){      // Resize if necessary
                  rcode = allocimage(&tempimage, tinfo.width * magnification / 100, tinfo.length  * magnification / 100, timage->bmh->biBitCount);
                  if(rcode == NO_ERROR) {
                     rcode = resizeex(timage, &tempimage, 1); // The Victor Library resize will be faster and better quality than a browser resize
                     if(rcode == NO_ERROR) {
                        freeimage(timage);
                        copyimgdes(&tempimage, timage);
                     }		               
                  }
               }
            }
         }
      }
   }
return(rcode);
} 
   
   
 // This function receives an image descriptor and sets up the gif or jpeg to be displayed   
unsafe int setup_to_displayimage(imgdes *lsrcimg)
{
byte * outbuff;
int mode=0;
int transcolor=0;
int rcode;
int quality=75;
string ftype = "image/gif";
int buffsize = 0;
byte [] imgbytearray;

   // Ready to display image. Use jpg for 24-bit images, gif for all others   
   if(lsrcimg->bmh->biBitCount == 24)
  	   {
         rcode = savejpgtobuffer (&outbuff, lsrcimg, quality);
         ftype = "image/jpeg";
    	   }
	else {
         rcode = savegiftobufferex (&outbuff, lsrcimg, mode, transcolor);
	   }
	   
	// Copy the jpeg or gif data into a byte array for sending to the browser      
   buffsize = getbuffersize(outbuff);
   imgbytearray = new byte[buffsize];
   if(buffsize > 0) {
      fixed(byte * iba = &imgbytearray[0])
      copybuffertobytearray(iba, outbuff, buffsize);
      }          
   
   // Store the image and file type in session variables   
   Session["outfilebinarydata"] = imgbytearray;
   Session["outfilecontent"] = ftype;

   image1.ImageUrl = "viewimage_cs.aspx";  // viewimage_cs.aspx will simply binary write the image to the browser   
   return(rcode);
   }
   
   
   		

Tiff Page View - Viewimage Source Code


//viewimage_cs.aspx Page_Load()  
void  Page_Load (object sender, EventArgs e){
string contentype;
byte [] imgbytearray;

   imgbytearray = (byte [])Session["outfilebinarydata"]; 
   contentype = (string)Session["outfilecontent"];

   Response.ContentType = contentype;
   Response.Expires = 0;
   Response.Buffer = true;
   Response.Clear();
   Response.BinaryWrite(imgbytearray);  // Send the image to the browser 
   Response.End();

}		

Victor Image Processing Library

Victor Image Processing Library homepage | Victor Product Summary | more source code

Copyright © 2006 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.