Multi-page TIFF images are displayed on the aspx page,

Source: Internet
Author: User

Multi-page TIFF images are displayed on the aspx page,

I. Logical implementation: Read Binary TIFF images from the database and display them on pages.

1. Display Interface

Public FrameDimension MyGuid; public static int MyPos = 0; public static int totalPage = 0; public static MemoryStream stream; protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {string username = Request. queryString ["username"]; string SQL = string. format ("select top (1) image from Image_Table where image_code = (select new_sjbh from new_ksy_dzpz where new_ksy_dzpzid = '{0}')", username); DataTable dt = SqlHelper. getTable (SQL); if (dt. rows. count> 0) {Image1.ImageUrl = "ShowImage. aspx? Username = "+ username +" & pagecount = 0 "; stream = new MemoryStream (byte []) dt. rows [0] ["image"]); // Bitmap bt = new Bitmap (Server. mapPath (Image1.ImageUrl); Bitmap bt = new Bitmap (stream); Guid gud = (Guid) bt. frameDimensionsList. getValue (0); FrameDimension fds = new FrameDimension (gud); totalPage = bt. getFrameCount (fds); // get the page number this. labelPageCount. text = totalPage. toString (); this. labelCurrentPage. te Xt = "1"; if (totalPage = 1) {this. linkButtonPreviousPage. enabled = false; // the previous page is read-only this. linkButtonFirstPage. enabled = false; // The homepage is read-only this. linkButtonNextPage. enabled = false; // next page read-only this. linkButtonLastPage. enabled = false; // The last page is read-only this. btnGo. enabled = false ;}} this. linkButtonPreviousPage. enabled = false; // the previous page is read-only this. linkButtonFirstPage. enabled = false; // homepage read-only} // download protected void Button1_Click (obj Ect sender, EventArgs e) {string username = Request. queryString ["username"]; string SQL = string. format ("select top (1) image, name from Image_Table where image_code = (select new_sjbh from new_ksy_dzpz where new_ksy_dzpzid = '{0}')", username); DataTable dt = SqlHelper. getTable (SQL); if (dt. rows. count> 0) {byte [] bytes = (byte []) dt. rows [0] ["image"]; // download a single credential Response. buffer = true; Page. response. Clear (); // Clear all the buffer content Page. response. contentType = "application/octet-stream"; Page. response. addHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. urlEncode (dt. rows [0] ["name"]. toString () + ". tiff "); Response. binaryWrite (bytes); Response. flush (); Response. end () ;}// next page protected void LinkButtonNextPage_Click (object sender, EventArgs e) {int page = Convert. toInt32 (this. labelCurrent Page. text); this. labelCurrentPage. text = Convert. toString (page + 1); fenyeshow (page) ;}// previous page protected void LinkButtonPreviousPage_Click (object sender, EventArgs e) {int page = Convert. toInt32 (this. labelCurrentPage. text)-2; this. labelCurrentPage. text = Convert. toString (page + 1); fenyeshow (page) ;}// homepage protected void LinkButtonFirstPage_Click (object sender, EventArgs e) {int page = 0; this. L AbelCurrentPage. text = "1"; fenyeshow (page);} // protected void LinkButtonLastPage_Click (object sender, EventArgs e) {int page = Convert. toInt32 (this. labelPageCount. text)-1; this. labelCurrentPage. text = this. labelPageCount. text; fenyeshow (page);} // Go protected void btnGo_Click (object sender, EventArgs e) {int page = 0; if (this.txt NewPageIndex. text! = "") {Int pagecount = Convert. toInt32 (this. labelPageCount. text); int txt = Convert.ToInt32(this.txt NewPageIndex. text); if (txt <= pagecount & txt> 0) {page = Convert.ToInt32(this.txt NewPageIndex. text)-1; this. labelCurrentPage. text = this.txt NewPageIndex. text ;}} if (page = 0) {this. labelCurrentPage. text = "1" ;}fenyeshow (page) ;}// display the public void fenyeshow (int pagecount) {string userna Me = Request. QueryString ["username"]; Image1.ImageUrl = "ShowImage. aspx? Username = "+ username +" & pagecount = "+ pagecount. toString (); if (this. labelCurrentPage. text = "1") {this. linkButtonPreviousPage. enabled = false; // the previous page is read-only this. linkButtonFirstPage. enabled = false; // The homepage is read-only this. linkButtonNextPage. enabled = true; this. linkButtonLastPage. enabled = true;} if (this. labelCurrentPage. text = this. labelPageCount. text) {this. linkButtonNextPage. enabled = false; // next page read-only this. linkButtonLastPage. enabled = false; // The last page is read-only this. linkButtonPreviousPage. enabled = true; this. linkButtonFirstPage. enabled = true ;}}Default. aspx

2. Output page

Public static MemoryStream stream; protected void Page_Load (object sender, EventArgs e) {string username = Request. queryString ["username"]; int pagecount = int. parse (Request. queryString ["pagecount"]); string SQL = string. format ("select top (1) image from Image_Table where image_code = (select new_sjbh from new_ksy_dzpz where new_ksy_dzpzid = '{0}')", username); DataTable dt = SqlHelper. getTable (SQL ); If (dt. rows. count> 0) {stream = new MemoryStream (byte []) dt. rows [0] ["image"]);} if (pagecount> = 0) {getImage (pagecount. toString () ;}} void getImage (string pp) // outputs the Jpeg format image stream based on the path {Bitmap bt = new Bitmap (stream); Guid gud = (Guid) bt. frameDimensionsList. getValue (0); FrameDimension fds = new FrameDimension (gud); if (pp! = "") {Int qq = Convert. toInt16 (pp); bt. selectActiveFrame (fds, qq);} MemoryStream ss = new MemoryStream (); bt. save (Server. mapPath ("1.jpg"); bt. save (ss, ImageFormat. jpeg); byte [] bb = ss. getBuffer (); ss. read (bb, 0, (int) ss. length); // this. ID_img.ImageUrl = Convert. toString (bb); Response. binaryWrite (bb); ss. close (); bt. dispose (); Response. end ();}ShowImage. aspx


Tips: The 1.jpg file is generated under the root directory. If the migration code is used, delete the 1.jpg file!

 

Related Article

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.