WebBrowser捕获图像错误

时间:2015-01-14 12:01:35

标签: c# asp.net image bitmap webbrowser-control

我使用WebBrowser创建一个位图,该应用程序在IIS Web服务器中被破坏,但该程序 抛出这样的异常错误HRESULT E_FAIL已从调用COM组件返回..变量文本是一个html代码包含JPG URL,[url]是(http://pic.ctrip.com/mail/iata_logo.png) 有人可以帮帮我吗?谢谢! 这是我的代码

            AutoResetEvent re = new AutoResetEvent(false);

            Thread tread = new Thread(delegate()
            {

                try
                {
                    MemoryStream mss = new MemoryStream();
                    System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
                    //wb.ScriptErrorsSuppressed = true;
                    wb.Navigate("about:blank");
                    wb.ScrollBarsEnabled = false;
                    wb.ClientSize = new Size(m_BrowserWidth, m_BrowserHeight);
                    //wb.ScrollBarsEnabled = false;

                    wb.Document.Write(text.ToString());
                    //wb.Refresh();
                    Bitmap m_Bitmap = new Bitmap(m_BrowserWidth, m_BrowserHeight);

                    //if (wb.ReadyState != WebBrowserReadyState.Complete)
                    //{
                    //    Application.DoEvents();
                    //}


                    System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(0, 0, m_BrowserWidth, m_BrowserHeight);
                    wb.DrawToBitmap(m_Bitmap, rectangle);
                    string fileName = "e:\\ddd" + Guid.NewGuid().ToString() + ".jpg";
                    m_Bitmap.Save(fileName);
                    m_Bitmap.Save(mss, System.Drawing.Imaging.ImageFormat.Jpeg);//JPG、GIF、PNG等均可  
                    buff = mss.ToArray();
                    re.Set();
                }
                catch (Exception ex)
                {

                    Console.WriteLine(ex);
                }
            });
            tread.SetApartmentState(ApartmentState.STA);
            tread.Start();
            re.WaitOne();

0 个答案:

没有答案