javascript 如何把网页(html)转成图片文件 或 用C#将html字符串生成网页后转化为图片

解决方案 »

  1.   

    javascript 如何把网页(html)转成图片文件
    不可能,javascript功能没这么强加。用C#将html字符串生成网页后转化为图片。
    这应该行的通,好像WinForm里有个WebBrower控件,用那个控件呈现html,然后截屏。
      

  2.   

            public Form1()
            {
                InitializeComponent();
                this.webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
            }        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                GetImage();
            }        void GetImage()
            {
                if (webBrowser1.Document == null) return;
                try
                {
                    int scrollHeight = webBrowser1.Document.Body.ScrollRectangle.Height;
                    int scrollWidth = webBrowser1.Document.Body.ScrollRectangle.Width;
                    webBrowser1.Size = new Size(scrollWidth, scrollHeight);
                    Bitmap bm = new Bitmap(scrollWidth, scrollHeight);
                    webBrowser1.DrawToBitmap(bm, new Rectangle(0, 0, bm.Width, bm.Height));
                    string saveAsName;
                    saveAsName = Regex.Replace(txtURL.Text, @"(\\|\/|\:|\*|\?|\""|\<|\>|\|)?", "");
                    bm.Save(saveAsName + ".png", System.Drawing.Imaging.ImageFormat.Png);
                    bm.Dispose();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "保存失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                }
                btnOK.Enabled = true;
            }        private void buttonCapture_Click(object sender, EventArgs e)
            {
                webBrowser1.Navigate(txtURL.Text);
                btnOK.Enabled = false;
            }
      

  3.   

    <embed height="150" width="950" flashvars="bannerWidth=950&bannerHeight=150&bannerSID=http://img.uu1001.cn/x2/2011-04-10/13-33/2011-04-10_ac42bdad242deb0bc67971ac720fcb25_0.xml&bannerXML=&bannerLink=http%3A%2F%2F&dataSource=&bid=20056046&appSource=default" wmode="transparent" allowscriptaccess="always" quality="high" name="20056046" id="20056046" style="" src="http://img.uu1001.cn/bcv3.swf?v=20110407" type="application/x-shockwave-flash"/></embed>
      

  4.   


    <embed height="150" width="950" flashvars="bannerWidth=950&bannerHeight=150&bannerSID=http://img.uu1001.cn/x2/2011-04-10/13-33/2011-04-10_ac42bdad242deb0bc67971ac720fcb25_0.xml&bannerXML=&bannerLink=http%3A%2F%2F&dataSource=&bid=20056046&appSource=default" wmode="transparent" allowscriptaccess="always" quality="high" name="20056046" id="20056046" style="" src="http://img.uu1001.cn/bcv3.swf?v=20110407" type="application/x-shockwave-flash"/></embed>