>
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
<%@ import namespace="viclib" %> // The tiff file is in a byte array in memory and we will load each page as requested int loadtiffdata(ref byte bd, ref vicwin.imgdes timage, int pindex, int magnification){ int rcode; vicwin.TiffData tinfo; int tpages=0; int noull=0; int lpage; vicwin.imgdes tempimage; int bpp=0; tinfo = new vicwin.TiffData(); tempimage = new vicwin.imgdes(); // Determine total pages in the file, put value in tpages rcode = vicwin.tiffgetpageinfofrombuffer(ref bd, ref tpages, ref noull, (int)0); if(rcode == vicwin.NO_ERROR){ numpages.Text = tpages.ToString( "0" ); lpage = tpages - 1; lastpage.Text = lpage.ToString( "0" ); // Get the image dimensions for the page of interest, put values into tinfo data structure rcode = vicwin.tiffinfopagebyindexfrombuffer(ref bd, ref tinfo, pindex); if(rcode == vicwin.NO_ERROR) { // Allocate space for the image in memory, timage is the image descriptor rcode = vicwin.allocimage(ref timage, tinfo.width, tinfo.length, tinfo.vbitcount); if(rcode == vicwin.NO_ERROR) { // Load the image from the tiff file into the image buffer described by timage rcode = vicwin.loadtifpagebyindexfrombuffer(ref bd, ref timage, pindex); if(rcode == vicwin.NO_ERROR || rcode == vicwin.BAD_DATA) { dimensions.Text = tinfo.width.ToString( "0" ) + " x " + tinfo.length.ToString( "0" ) + " " + tinfo.vbitcount.ToString( "0" ) + "-bit"; if(tinfo.vbitcount == 16){ // Replace 16-bit grayscale image with 8-bit grayscale rcode = vicwin.allocimage(ref tempimage, tinfo.width, tinfo.length, 8); rcode = vicwin.convertgray16to8(ref timage, ref tempimage); if(rcode == vicwin.NO_ERROR) { vicwin.freeimage(ref timage); vicwin.copyimgdes(ref tempimage, ref timage); } } if(magnification != 100){ // Resize if necessary bpp = getbpp(ref timage); rcode = vicwin.allocimage(ref tempimage, tinfo.width * magnification / 100, tinfo.length * magnification / 100, bpp); if(rcode == vicwin.NO_ERROR) { // The Victor Library resize will be faster and better quality than a browser resize rcode = vicwin.resizeex(ref timage, ref tempimage, 1); if(rcode == vicwin.NO_ERROR) { vicwin.freeimage(ref timage); vicwin.copyimgdes(ref tempimage, ref timage); } } } } } } } else // Error loading tiff file { numpages.Text = "0"; lastpage.Text = "0"; } return(rcode); } // This function receives an image descriptor and sets up the gif or jpeg to be displayed int setup_to_displayimage(ref vicwin.imgdes lsrcimg) { int outbuff=0; int mode=0; int transcolor=0; int rcode; int quality=75; string ftype = "image/gif"; int buffsize = 0; byte [] imgbytearray= {0,0,0}; int bpp; bpp = getbpp(ref lsrcimg); // Ready to display image. Use jpg for 24-bit images, gif for all others if(bpp == 24) { rcode = vicwin.savejpgtobuffer (ref outbuff, ref lsrcimg, quality); ftype = "image/jpeg"; } else { rcode = vicwin.savegiftobufferex (ref outbuff, ref lsrcimg, mode, transcolor); } // Copy the jpeg or gif data into a byte array for sending to the browser if(rcode == vicwin.NO_ERROR) { imgbytearray = transferbuffertobytearray(outbuff); vicwin.freebuffer(outbuff); } // Store the image and file type in session variables Session["outfilebinarydata"] = imgbytearray; Session["outfilecontent"] = ftype; // viewimage_cs.aspx will simply binary write the image to the browser image1.ImageUrl = "viewimage_cs.aspx"; return(rcode); }
// viewimage_cs.aspx 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 homepage | Victor Product Summary | more source code
Copyright © 2006 - 2007 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.