convert div content into image
2013-05-15 18:01
477 查看
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing.Imaging; using System.Windows.Forms; using System.Threading; public partial class Image_Generate_CreateImageForDiv : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } System.Drawing.Bitmap bitMap=null; protected void btnGenerateImage_Click(object sender, EventArgs e) { LetUserDownload(); } public void DisplayImage() { //ApartmentState:specifies the state of a system.threading.thread //STA:Thread will create and enter a single-threaded apartment Thread t = new Thread(CaptureWebPageToDisplay); t.SetApartmentState(ApartmentState.STA); t.Start("http://localhost/"); Thread.Sleep(5000); Response.ContentType = "image/jpeg"; bitMap.Save(Response.OutputStream, ImageFormat.Jpeg); bitMap.Dispose(); bitMap.Dispose(); Response.Flush(); } public void LetUserDownload() { //ApartmentState:specifies the state of a system.threading.thread //STA:Thread will create and enter a single-threaded apartment Thread t = new Thread(CaptureWebPageToDisplay); t.SetApartmentState(ApartmentState.STA); t.Start("http://localhost/"); Thread.Sleep(5000); Response.Clear(); Response.ContentType = "image/jpeg"; Response.AddHeader("content-disposition", "attachment;filename=imageafda.jpeg"); string filePath = Server.MapPath("~/Images")+ "/FileName.Jpeg"; bitMap.Save(filePath , ImageFormat.Jpeg); bitMap.Dispose(); Response.WriteFile(filePath); Response.Flush(); } public void CaptureWebPageToDisplay(object URL) { // create a hidden web browser, which will navigate to the page System.Windows.Forms.WebBrowser web = new System.Windows.Forms.WebBrowser(); // we don't want scrollbars on our image web.ScrollBarsEnabled = false; // don't let any errors shine through web.ScriptErrorsSuppressed = true; // let's load up that page! web.Navigate((string)URL); // wait until the page is fully loaded while (web.ReadyState != WebBrowserReadyState.Complete) System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(1500); // allow time for page scripts to update // the appearance of the page // set the size of our web browser to be the same size as the page int width = web.Document.Body.ScrollRectangle.Width; int height = web.Document.Body.ScrollRectangle.Height; web.Width = width; web.Height = height; // a bitmap that we will draw to System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height); // draw the web browser to the bitmap web.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, width, height)); bitMap = bmp; } }
相关文章推荐
- convert div into image
- convert RGB image with hole into binary image with hole filled
- Make3D Convert your image into 3d model(from standford)
- Make3D Convert your image into 3d model
- Make3D Convert your image into 3d model
- android studio imageview src Failed convert xxxx into drawable xxxx
- Android ImageView设置长度高度为wrap_content时高度根据图片比例自适应
- 基于内容的图像检索技术(Content-Based Image Retrieval,CBIR)
- convert image to base64 and post to RESTful wcf
- Convert an object into Json using SBJson or other JSON library
- Missing contentDescription attribute on image
- Android ImageView设置长度高度为wrap_content时高度根据图片比例自适应
- [Accessibility] Missing contentDescription attribute on image .
- UITableViewCell 的Image设置了UIViewContentModeScaleAspectFill后图片超出去了
- Android(3)---[Accessibility] Missing contentDescription attribute on image解决办法
- [Accessibility] Missing contentDescription attribute on image
- 使用yii的layout,加入<?php echo $content; ?>这句话时,它会自动在子页面上面添加一个div包裹
- Convert DateTime Value into String in Mysql
- <div class="article_content tracking-ad" id="article_content" data-mod="popu_307" data-dsm="post"> <
- css3实现一个div设置多张背景图片及background-image属性