Display a multi-page tif file on the web page

Source: Internet
Author: User

1. display the TIFF image with the specified index page number

1. display on the page

On the display page:

Display method similar to verification code

Showtif. ASPX pageCodeWrite as follows: (this page does not contain background code)

<% @ Page Language = "C #" %>

<% @ Import namespace = "test" %>

<% Bind. showmultif ("img/AAA. tif", 1); %>

The showmultif method is defined as follows:

/**/ ///   <Summary>
/// Display multi-page TIF Images
///   </Summary>
///   <Param name = "fielname"> File Name </Param>
///   <Param name = "Index"> Display page number </Param>
Public   Static   Void Showmultif ( String Fielname, Int Index)
{
Httpcontext Context = Httpcontext. Current;
String Bgfilepath = Context. server. mappath (fielname );
System. Drawing. Image imgobj = System. Drawing. image. fromfile (bgfilepath );

// Obtain the image on the index page
Guid objguid = (Imgobj. framedimensionslist [ 0 ]);
System. Drawing. imaging. framedimension objdimension = New System. Drawing. imaging. framedimension (objguid );
// Total number of pages
Int Totframe;
Totframe = Imgobj. getframecount (objdimension );

If (Index > Totframe)
Index = Totframe;
If (Index < 1 )
Index = 1 ;

Imgobj. selectactiveframe (objdimension, index );


// Set the output MIME type
Context. response. contenttype =   " Image/GIF " ;
// Output file to the browser
//
Imgobj. Save (context. response. outputstream, system. Drawing. imaging. imageformat. GIF );
// Release resources
Context. response. Flush ();
Context. response. End ();
}

2. Use ioffice tools or image viewer to browse images by downloading and opening them

Ii. Convert TIF to JPG files

Convert TIF to multiple jpge or GIF

Public Int Savepic ( String Fullpath, Int Index)
{
// Make the specified page number within the range of this image
If (Index < 0 | Index > This . Framenumber)
{
Index=0;
}

// Draws a specified page to savegif, where savegif is the specified size.
Point ulcorner = New Point ( 0 , 0 );
Point urcorner = New Point ( This . Savewidth, 0 );
Point llcorner = New Point ( 0 , This . Saveheight );
Point [] destpara = {Ulcorner, urcorner, llcorner} ;

Savegif = New Bitmap ( This . Savewidth, This . Saveheight );
Graphics save = Graphics. fromimage (savegif );
Opentif. selectactiveframe (framedime, index );
Save. drawimage (opentif, destpara );
Save. Dispose ();
Save = Null ;

// Save Images
Savegif. Save (fullpath, imageformat. GIF );
Savegif. Dispose ();
Savegif = Null ;

Return 1 ;
}  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.