none
Website screenshot 제작 관련 문의입니다. RRS feed

  • 질문

  • Website screenshot 관련 class를 제작중에 있는데 계속 알 수 없는 에러가 나옵니다.
    에러 네용은

    "현재 스레드가 단일 스레드 아파트에 없으므로 ActiveX 컨트롤 '8856f961-340a-11d0-a96b-00c04fd705a2'을
    (를) 인스턴스화할 수 없습니다."
    라는 메시지가 나오고,

    소스는 일단 dll파일은

    using System;
    using System.Collections.Generic;
    using System.Text;

    using System.IO;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Drawing.Drawing2D;

    using System.Windows.Forms;




    namespace GetSiteThumbnail
    {
      

        /*
        public static void Main()
        {
            Application.Run(new 폼네임());
        }
        */

        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;

            }

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

        }


        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.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 = default(Rectangle);
                oRectangle = new Rectangle(0, 0, twidth, theight);
                g.DrawImage(imgOutput, oRectangle);
                try
                {
                    return  oThumbNail;
                }
                catch (Exception ex)
                {
                    throw ex;

                }
                finally
                {
                    imgOutput.Dispose();
                    imgOutput = null;
                    MyBrowser.Dispose();
                    MyBrowser = null;
                }
            }
        }
    }


    그리고 실제 asp.net 페이지에는
    GetSiteThumbnail.GetImage oImg = new GetSiteThumbnail.GetImage("http://naver.com", 1000, 800, 500,
    400);

             oImg.GetBitmap();

    이런 식으로 처리 했는데 에러가 나오네요.

    아마도 스레드 관련 문제인것 같은데
    위의 소스를 웹에서 사용가능한 단일 스레드로 만들려면 어떻게 해야하는지 도움 부탁드리겠습니다
    2009년 5월 8일 금요일 오후 3:11