All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
构建可配置PHP应用程序的正确方式_php资料_编程技术
ASP.NET实现投票结果的图片进度条显示代码_.net资料_编程技术
PHP程序处理网页表单的GET和POST方法另外用法_php资料_编程技术
vbscript下将小写金额转成大写金额_JavaScript技术_编程技术
Delphi主菜单组件(TMainMenu)技巧
ASP.NET技巧:Web导出Word需要添加头文件_[Asp.Net教程]
PHP技巧:PHP关于中文汉字替换与模式匹配的问题_[PHP教程]
如何创建SQL Server 2000故障转移群集_[SQL Server教程]
php时间加减_php资料_编程技术
Windows,XP操作系统下的MYSQL安装过程_php资料_编程技术
Reading number is top 10 pictures
The money of more than 100 countries and regions20
人物写真-谢楠
这玉米,买还是不卖?
Ashlynn Brooke photograph of a group4
More attractive than sora aoi1
Summer is most suitable for young people to travel in China1
美女挤公交
A resort photographed beautiful young woman change clothes process vomiting blood2
西游日记1
Li Zongrui hunting video screenshots2
Download software ranking
Unix video tutorial17
Sora aoi 120 minutes
美女写真3
Unix video tutorial14
传奇私服架设教程-chm
Tram sex maniac 2 (H) rar bag5
Rio big adventure
C#高级编程(第4版)
jdk1.6 for windows
White deer villiage
归海一刀 published in(发表于) 2014/1/30 1:00:00 Edit(编辑)
Asp.Net对指定的网页截图_[Asp.Net教程]

Asp.Net对指定的网页截图_[Asp.Net教程]

Asp.Net对指定的网页截图_[Asp.Net教程]

首先对项目添加系统引用
System.Drawing;
System.Drawing.Design;
System.Windows.Forms;

获取指定网页并转换成图片的类:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Diagnostics;

namespace MyLib
{
public class GetImage
{
private int S_Height;
private int S_Width;
private int F_Height;
private int F_Width;
private 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.ScreenWidth = ScreenWidth;
this.ScreenHeight = ScreenHeight;
this.ImageHeight = ImageHeight;
this.ImageWidth = ImageWidth;
}

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;
}
}

class WebPageBitmap
{
WebBrowser MyBrowser;
string URL;
int Height;
int Width;

public WebPageBitmap(string url, int width, int height)
{
this.Height = height;
this.Width = width;
this.URL = url;
MyBrowser = new WebBrowser();
MyBrowser.ScrollBarsEnabled = false;
MyBrowser.Size = new Size(this.Width, this.Height);
}

public void GetIt()
{
MyBrowser.Navigate(this.URL);
while (MyBrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
}

public Bitmap DrawBitmap(int theight, int twidth)
{
Bitmap myBitmap = new Bitmap(Width, Height);
Rectangle DrawRect = new Rectangle(0, 0, Width, Height);
MyBrowser.DrawToBitmap(myBitmap, DrawRect);
System.Drawing.Image imgOutput = myBitmap;
System.Drawing.Image oThumbNail = new Bitmap(twidth, theight, imgOutput.PixelFormat);
Graphics g = Graphics.FromImage(oThumbNail);
g.CompositingQuality = CompositingQuality.HighSpeed;
g.SmoothingMode = SmoothingMode.HighSpeed;
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
Rectangle oRectangle = new Rectangle(0, 0, twidth, theight);
g.DrawImage(imgOutput, oRectangle);
try
{

return (Bitmap)oThumbNail;
}
catch (Exception ex)
{
return null;
}
finally
{
imgOutput.Dispose();
imgOutput = null;
MyBrowser.Dispose();
MyBrowser = null;
}
}
}

}


以下是调用方法,懒省事的方法,嘿嘿,赶时间就不说什么了,反正上面的抓取转换类已经写出来了,大家尽情的用异步,线程等方法自己玩吧!~

string UrlPath;
bool CaptureState = false;
Guid guid;
protected bool SaveOriginalPageToImage(Guid myGuid)
{
//使用guid 来命名
guid = myGuid;
if (this.CurrentPageAct == PageAct.Edit)
{
string PagePath = Request.Url.LocalPath;
PagePath = PagePath.Replace("Operation", "Capture");

UrlPath = PagePath + "?act=view&ProjectNo=" + _projectNo;

Thread NewTh = new Thread(CaptureImage);
NewTh.SetApartmentState(ApartmentState.STA);
NewTh.Start();
while (NewTh.ThreadState == ThreadState.Running)
{
}
//返回截取状态
return CaptureState;
}
return false;
}

/**//**//**////


/// 捕获屏幕
///

///
///
public void CaptureImage()
{
try
{
string url = "http://" + Request.Url.Host + ":" + Request.Url.Port.ToString();
url = url + UrlPath;

GetImage thumb = new GetImage(url, 1024, 1200, 1024, 1200);
System.Drawing.Bitmap x = thumb.GetBitmap();
string FileName = DateTime.Now.ToString("yyyyMMddhhmmss");

x.Save(Server.MapPath("~/Capture/SavePage") + "\" + guid + ".jpg");
CaptureState = true;
}
catch (Exception ex)
{
CaptureState = false;
}
}


来源:csdn







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.