最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET實(shí)現(xiàn)根據(jù)URL生成網(wǎng)頁縮略圖的方法

 更新時(shí)間:2015年11月18日 10:18:05   作者:mile  
這篇文章主要介紹了ASP.NET實(shí)現(xiàn)根據(jù)URL生成網(wǎng)頁縮略圖的方法,結(jié)合實(shí)例較為詳細(xì)的分析了asp.net生成網(wǎng)頁縮略圖的詳細(xì)實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了ASP.NET實(shí)現(xiàn)根據(jù)URL生成網(wǎng)頁縮略圖的方法。分享給大家供大家參考,具體如下:

工作中需要用到根據(jù)URL生成網(wǎng)頁縮略圖功能,提前做好準(zhǔn)備。

在網(wǎng)上找了份源碼,但是有錯(cuò)誤:當(dāng)前線程不在單線程單元中,因此無法實(shí)例化 ActiveX 控件“8856f961-340a-11d0-a9”,解決后運(yùn)行良好,記錄在此備用!

起始頁:Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CaptureToImage._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
 <title>Snap</title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 <input type="button" onclick="window.open('Snap.aspx?url=www.njude.com.cn')" value="生成網(wǎng)頁縮略圖"/>
 </div>
 </form>
</body>
</html>

調(diào)用頁:Snap.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Snap.aspx.cs" Inherits="CaptureToImage.Snap" AspCompat="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
 <title>無標(biāo)題頁</title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 </div>
 </form>
</body>
</html>

PS:紅色字體部分是為解決錯(cuò)誤增加的代碼,強(qiáng)制程序在單線程環(huán)境下運(yùn)行!

調(diào)用頁:Snap.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing.Imaging;
namespace CaptureToImage
{
 public partial class Snap : System.Web.UI.Page
 {
  protected void Page_Load(object sender, EventArgs e)
  {
   string url = string.Empty;
   url = Request.QueryString[0];
   try
   {
    GetImage thumb = new GetImage(url, 1024, 768, 800, 600);
    System.Drawing.Bitmap x = thumb.GetBitmap();
    x.Save(Response.OutputStream, ImageFormat.Jpeg);
    Response.ContentType = "image/jpeg";
   }
   catch (Exception ex)
   {
    Response.Write(ex.Message);
   }
  }
 }
}

類文件:GetImage.cs

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Web.UI;
namespace CaptureToImage
{
 public class GetImage
 {
  int S_Height;
  int S_Width;
  int F_Height;
  int F_Width;
  string MyURL;
  public int ScreenHeight
  {
   get
   {
    return S_Height;
   }
   set
   {
    S_Height = value;
   }
  }
  public int ScreenWidth
  {
   get
   {
    return S_Width;
   }
   set
   {
    S_Width = value;
   }
  }
  public int ImageHeight
  {
   get
   {
    return F_Height;
   }
   set
   {
    F_Height = value;
   }
  }
  public int ImageWidth
  {
   get
   {
    return F_Width;
   }
   set
   {
    F_Width = value;
   }
  }
  public string WebSite
  {
   get
   {
    return MyURL;
   }
   set
   {
    MyURL = value;
   }
  }
  public GetImage(string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight)
  {
   this.WebSite = WebSite;
   this.ScreenHeight = ScreenHeight;
   this.ScreenWidth = ScreenWidth;
   this.ImageHeight = ImageHeight;
   this.ImageWidth = ImageWidth;
  }
  [STAThread]
  public Bitmap GetBitmap()
  {
   WebPageBitmap Shot = new WebPageBitmap(this.WebSite, this.ScreenWidth, this.ScreenHeight);
   Shot.GetIt();
   Bitmap Pic = Shot.DrawBitmap(this.ImageHeight, this.ImageWidth);
   return Pic;
  }
 }
 public class WebPageBitmap
 {
  WebBrowser MyBrowser;
  string URL;
  int Height;
  int Width;
  public WebPageBitmap(string url, int width, int height)
  {
   this.URL = url;
   this.Width = width;
   this.Height = height;
   MyBrowser = new WebBrowser();
   MyBrowser.ScrollBarsEnabled = false;
   MyBrowser.Size = new Size(this.Width, this.Height);
  }
  public void GetIt()
  {
   NavigateUrl(this.URL);
   while (MyBrowser.ReadyState != WebBrowserReadyState.Complete)
   {
    Application.DoEvents();
   }
  }
  public delegate void DelUserHandler(string url);
  public void NavigateUrl(string url)
  {
   try
   {
    if (this.MyBrowser.InvokeRequired)
    {
     DelUserHandler handler = new DelUserHandler(NavigateUrl);
     MyBrowser.Invoke(handler, url);
    }
    else
    {
     this.MyBrowser.Navigate(url);
    }
   }
   catch (Exception ex)
   {
    throw new Exception("NavigateUrl()" + ex.Message);
   }
  }
  public Bitmap DrawBitmap(int theight, int twidth)
  {
   Bitmap myBitmap = new Bitmap(this.Width, this.Height);
   Rectangle DrawRect = new Rectangle(0, 0, this.Width, this.Height);
   MyBrowser.DrawToBitmap(myBitmap, DrawRect);
   System.Drawing.Image imgOutput = myBitmap;
   System.Drawing.Bitmap oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
   Graphics g = Graphics.FromImage(oThumbNail);
   g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
   g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
   g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
   Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);
   g.DrawImage(imgOutput, oRectangle);
   try
   {
    return oThumbNail;
   }
   catch
   {
    return null;
   }
   finally
   {
    imgOutput.Dispose();
    imgOutput = null;
    MyBrowser.Dispose();
    MyBrowser = null;
   }
  }
 }
}

PS:項(xiàng)目中需要添加引用System.Windows.Forms

希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • .NET?6開發(fā)TodoList應(yīng)用實(shí)現(xiàn)系列背景

    .NET?6開發(fā)TodoList應(yīng)用實(shí)現(xiàn)系列背景

    這篇文章主要介紹了.NET?6開發(fā)TodoList應(yīng)用實(shí)現(xiàn)系列背景,NET?6是一個(gè)很優(yōu)秀的框架,這一點(diǎn)自從我最開始接觸.NET?Core?2起一年一年進(jìn)化到現(xiàn)在,就深切地感受到,那好東西就拿出來和大家分享一下,下面來看一下文章的學(xué)習(xí)介紹吧
    2021-12-12
  • ASP.NET?Core使用EF創(chuàng)建關(guān)系模型

    ASP.NET?Core使用EF創(chuàng)建關(guān)系模型

    這篇文章介紹了ASP.NET?Core使用EF創(chuàng)建關(guān)系模型的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • 手把手帶你定制.NET?6.0的Middleware中間件

    手把手帶你定制.NET?6.0的Middleware中間件

    .NET?6?發(fā)布后,我們現(xiàn)有的應(yīng)用會(huì)逐步升級(jí)到這個(gè)版本,下面這篇文章主要給大家介紹了關(guān)于定制.NET?6.0的Middleware中間件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-12-12
  • asp.net session的使用與過期實(shí)例代碼

    asp.net session的使用與過期實(shí)例代碼

    本文章來簡單的介紹asp.net中session常見兩種用法,一種是session使用如何創(chuàng)建,另一種是告訴你如何判斷session過期了,有需要了解的朋友可以參考一下
    2013-08-08
  • WPF實(shí)現(xiàn)雷達(dá)掃描圖的繪制詳解

    WPF實(shí)現(xiàn)雷達(dá)掃描圖的繪制詳解

    這篇文章主要介紹了如何利用WPF實(shí)現(xiàn)雷達(dá)掃描圖的繪制,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,需要的可以參考一下
    2022-05-05
  • .net中string類型可以作為lock的鎖對(duì)象嗎

    .net中string類型可以作為lock的鎖對(duì)象嗎

    lock 關(guān)鍵字是用于在多線程編程中實(shí)現(xiàn)同步和互斥訪問的關(guān)鍵字,它的作用是確保共享資源在任意時(shí)刻只能被一個(gè)線程訪問,從而避免出現(xiàn)競態(tài)條件(race condition)和數(shù)據(jù)不一致的問題,這篇文章主要介紹了string類型可以作為lock的鎖對(duì)象嗎,需要的朋友可以參考下
    2023-06-06
  • 樹莓派ASP.NET環(huán)境配置過程詳解

    樹莓派ASP.NET環(huán)境配置過程詳解

    這篇文章主要介紹了樹莓派ASP.NET環(huán)境配置,本篇文章內(nèi)容是根據(jù)mono官網(wǎng)上查閱的配置教程所寫,需要的朋友可以參考下
    2022-04-04
  • asp.net全局變量的實(shí)例方法

    asp.net全局變量的實(shí)例方法

    在本篇文章里小編給大家整理的是關(guān)于asp.net全局變量的實(shí)例方法和實(shí)例,需要的朋友們可以學(xué)習(xí)下。
    2020-02-02
  • 使用Seq搭建免費(fèi)的日志服務(wù)的方法

    使用Seq搭建免費(fèi)的日志服務(wù)的方法

    這篇文章主要介紹了使用Seq搭建免費(fèi)的日志服務(wù)的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Asp.net 2.0 無刷新圖片上傳 顯示縮略圖 具體實(shí)現(xiàn)

    Asp.net 2.0 無刷新圖片上傳 顯示縮略圖 具體實(shí)現(xiàn)

    簡單三步實(shí)現(xiàn)圖片無刷新上傳:注意是上傳,至于上傳時(shí)的驗(yàn)證,比如圖片的尺寸,大小,格式。自行解決。如果我搞定了,也會(huì)貼上來的。
    2013-06-06

最新評(píng)論

安徽省| 商河县| 泗洪县| 旺苍县| 济宁市| 宜阳县| 嘉祥县| 河东区| 阜阳市| 黔东| 合山市| 利川市| 本溪市| 定南县| 互助| 揭阳市| 辽阳市| 昆山市| 即墨市| 松阳县| 伊金霍洛旗| 海宁市| 年辖:市辖区| 宜兰县| 综艺| 崇左市| 淳安县| 大宁县| 边坝县| 安陆市| 商城县| 依兰县| 阆中市| 信丰县| 随州市| 体育| 长汀县| 交城县| 舟山市| 沾化县| 视频|