麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 編程 > .NET > 正文

ASP.NET中圖片顯示方法實(shí)例

2024-07-10 13:29:15
字體:
供稿:網(wǎng)友
這篇文章主要介紹了ASP.NET中圖片顯示方法,實(shí)例分析了ASP.NET圖片顯示所涉及的圖片路徑、縮略圖及更新數(shù)據(jù)庫(kù)圖片瀏覽次數(shù)等相關(guān)技巧,需要的朋友可以參考下
 

本文實(shí)例講述了ASP.NET中圖片的顯示方法。分享給大家供大家參考。具體如下:

genimage.ashx:

復(fù)制代碼代碼如下:
<%@ WebHandler Language="C#" Class="netpix.ImageGenerator" %>

 

genimage.ashx.cs:
 

  1. // Copyright (C) 2003 by Greg Ennis 
  2. // (mailto:[email protected]) 
  3. // 
  4. // The contents of this file are subject to the Artistic License (the "License"). 
  5. // You may not use this file except in compliance with the License.  
  6. // You may obtain a copy of the License at: 
  7. // http://www.opensource.org/licenses/artistic-license.html 
  8. using System; 
  9. using System.Collections; 
  10. using System.ComponentModel; 
  11. using System.Data; 
  12. using System.Data.SqlClient; 
  13. using System.Drawing; 
  14. using System.Web; 
  15. using System.IO; 
  16. using System.Configuration; 
  17. using System.Web.SessionState; 
  18. using System.Web.UI; 
  19. using System.Web.UI.WebControls; 
  20. using System.Web.UI.HtmlControls; 
  21. namespace netpix 
  22.   public class ImageGenerator : IHttpHandler  
  23.   {  
  24.     public bool IsReusable  
  25.     { get { return true; } }  
  26.     public void ProcessRequest(HttpContext Context)  
  27.     {  
  28.       // Get the image filename and album root path from the database 
  29.       //圖片瀏覽次數(shù) 
  30.       int numviews; 
  31.       //圖片數(shù)據(jù)庫(kù)中的ID 
  32.       int picid = Convert.ToInt32(Context.Request["id"]); 
  33.       //圖片路徑  
  34.       string imgpath = npdata.GetPathToPicture(picid, out numviews); 
  35.       // Writing an image to output stream 
  36.       Context.Response.ContentType = "image/jpg"
  37.       // 'thumbnail' means we are requesting a thumbnail 
  38.       //顯示縮略圖 
  39.       if (Context.Request["thumbnail"] != null
  40.       { 
  41.         // Need to load the image, resize it, and stream to the client. 
  42.         // Calculate the scale so as not to stretch or distort the image. 
  43.         Bitmap bmp = new Bitmap(imgpath); 
  44.         float scale = 150.0f / System.Math.Max(bmp.Height, bmp.Width); 
  45.         System.Drawing.Image thumb = bmp.GetThumbnailImage((int)(bmp.Width * scale), (int)(bmp.Height * scale), null, System.IntPtr.Zero); 
  46.         thumb.Save(Context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); 
  47.         bmp.Dispose(); 
  48.         thumb.Dispose(); 
  49.       } 
  50.       else 
  51.       { 
  52.         // Stream directly from the file 
  53.         // Get the stream and send it out the response 
  54.         System.IO.FileStream fs = File.Open(imgpath, FileMode.Open, FileAccess.Read, FileShare.Read); 
  55.         const int byteLength = 8192; 
  56.         byte[] bytes = new byte[byteLength]; 
  57.         while( fs.Read(bytes, 0, byteLength ) != 0 ) 
  58.         { 
  59.           Context.Response.BinaryWrite(bytes);  
  60.         } 
  61.         fs.Close(); 
  62.         //更新數(shù)據(jù)庫(kù)瀏覽次數(shù) 
  63.         npdata.SetNumViews(picid, numviews+1); 
  64.       } 
  65.     } 
  66.   } 
?
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 国产亚洲精品久久久久久久 | 久久精品视频16 | 国内精品视频饥渴少妇在线播放 | h视频免费在线 | 91精品国产777在线观看 | 国产毛片自拍 | 27xxoo无遮挡动态视频 | 免费毛片儿 | 免费在线看a| jizzzxxxxhd| 精品国产一区二区三区久久久 | 91午夜理伦私人影院 | 国产青草视频在线观看 | 国产一级毛片国语版 | 看免费的毛片 | 亚洲无毛av | 国产1区2区在线 | 欧美一级aa免费毛片 | 一级毛片真人免费播放视频 | 中国杭州少妇xxxx做受 | 久久草在线视频 | 91福利社在线 | 国产精品久久久久久影院8一贰佰 | 成人wxx视频免费 | www.com香蕉| 欧美一级美片在线观看免费 | 国产一区精品在线观看 | 韩国三级日本三级香港三级黄 | 天天看成人免费毛片视频 | 韩国19禁在线 | 九九热精 | 精品人成| 日本在线观看视频网站 | 欧美一级电影网 | 黄网站在线播放视频免费观看 | 性 毛片 | 欧美性生交大片 | av成人免费看 | 91美女福利视频 | 久久经典国产视频 | 亚洲一区二区三区精品在线观看 |