Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Browser   browser = new IE("http://www.google.com");
            IEElement banner  = browser.Images[0].NativeElement as IEElement;

            IHTMLElement bannerHtmlElem = banner.AsHtmlElement;
            IEElement    bodyNative     = browser.Body.NativeElement as IEElement;

            mshtml.IHTMLElement2     bodyHtmlElem = (mshtml.IHTMLElement2)bodyNative.AsHtmlElement;
            mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)bodyHtmlElem.createControlRange();

            controlRange.add((mshtml.IHTMLControlElement)bannerHtmlElem);
            controlRange.execCommand("Copy", false, System.Reflection.Missing.Value);
            controlRange.remove(0);

            if (Clipboard.GetDataObject() != null)
            {
                IDataObject data = Clipboard.GetDataObject();
                if (data.GetDataPresent(DataFormats.Bitmap))
                {
                    System.Drawing.Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true);
                    // do something here
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 웹에 이미지를 폴더에 저장한다.
        /// </summary>
        /// <param name="FolderPath"></param>
        public void AllImage_Save(string FolderPath)
        {
            string strElName;

            mshtml.IHTMLElement2     body2        = (mshtml.IHTMLElement2)HTMLDoc.body;
            mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)body2.createControlRange();
            IHTMLElementCollection   imgs         = HTMLDoc.images;


            foreach (mshtml.HTMLImg objImg in imgs)
            {
                controlRange.add((mshtml.IHTMLControlElement)objImg);
                controlRange.execCommand("Copy", false, System.Reflection.Missing.Value);
                controlRange.remove(0);
                strElName = objImg.nameProp;

                if (Clipboard.GetDataObject() != null)
                {
                    IDataObject data = Clipboard.GetDataObject();

                    if (data.GetDataPresent(DataFormats.Bitmap))
                    {
                        Image image = (Image)data.GetData(DataFormats.Bitmap, true);
                        if (strElName.Substring(strElName.IndexOf(".") + 1).ToLower() == "jpg")
                        {
                            image.Save(FolderPath + strElName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        else if (strElName.Substring(strElName.IndexOf(".") + 1).ToLower() == "gif")
                        {
                            image.Save(FolderPath + strElName, System.Drawing.Imaging.ImageFormat.Gif);
                        }
                        else if (strElName.Substring(strElName.IndexOf(".") + 1).ToLower() == "png")
                        {
                            image.Save(FolderPath + strElName, System.Drawing.Imaging.ImageFormat.Png);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 이미지 이름으로 찾는다.
        /// </summary>
        /// <param name="imgName">이미지파일명이나 herf 경로</param>
        /// <returns></returns>
        public Image Image_Get(string imgName)
        {
            string strElName;

            mshtml.IHTMLElement2     body2        = (mshtml.IHTMLElement2)HTMLDoc.body;
            mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)body2.createControlRange();
            IHTMLElementCollection   imgs         = HTMLDoc.images;

            Image image = null;

            foreach (mshtml.HTMLImg objImg in imgs)
            {
                if (objImg.nameProp != imgName && objImg.href != imgName)
                {
                    continue;
                }


                controlRange.add((mshtml.IHTMLControlElement)objImg);
                controlRange.execCommand("Copy", false, System.Reflection.Missing.Value);
                controlRange.remove(0);
                strElName = objImg.nameProp;

                if (Clipboard.GetDataObject() != null)
                {
                    IDataObject data = Clipboard.GetDataObject();

                    if (data.GetDataPresent(DataFormats.Bitmap))
                    {
                        image = (Image)data.GetData(DataFormats.Bitmap, true);
                    }
                }
            }

            return(image);
        }