Esempio n. 1
0
        private bool HtmlImgCompare(string html, string imgPath)
        {
            string temphtmlPath = SpecialDirectories.Temp + "\\SUITemp.html";

            if (File.Exists(imgPath))
            {
                SUIBitmap standardImg = SUIBitmap.LoadSUIBitmap(imgPath);
                if (standardImg == null)
                {
                    throw (new SUIHtmlCompareException());
                }
                try
                {
                    SUIUtil.OutputFileFromString(html, temphtmlPath);
                    SUIIE     ie      = SUIIE.CreateIEWithURL(temphtmlPath);
                    SUIBitmap tempImg = ie.GetClientArea();
                    // Fix a bug: we need to assign image path to the captured temp SUIBitmap object.
                    tempImg.Path = imgPath;
                    //SUIIE.CleanIEProcess();
                    SUIImageComparer Comparer = new SUIImageComparer();
                    return(Comparer.Compare(standardImg, tempImg));
                }catch (SUIException e)
                {
                    throw(new SUIHtmlCompareException(e));
                }
            }
            else
            {
                try
                {
                    SUIUtil.OutputFileFromString(html, temphtmlPath);
                    SUIIE     ie      = SUIIE.CreateIEWithURL(temphtmlPath);
                    SUIBitmap tempImg = ie.GetClientArea();
                    //SUIIE.CleanIEProcess();
                    tempImg.Path = imgPath;
                    tempImg.Save();
                    return(true);
                }
                catch (SUIException e)
                {
                    throw (new SUIHtmlCompareException(e));
                }
            }
        }
Esempio n. 2
0
        public static SUIBitmap GetImageFromWindow(SUIWindow sui, bool withCursor)
        {
            if (null != sui)
            {
                SUISleeper.Sleep(2000);  //make sure paint compldte!
                //Rectangle rDialog = new Rectangle();
                try
                {
                    if (!sui.ClassName.Equals("#32768"))
                    {
                        sui.BringToTopMost();
                        sui.ShowShortCutIndicators();
                        if (!withCursor)
                        {
                            SUIWinAPIs.SetCursorPos(SUIWindow.DesktopWindow.Width / 2, 0);// Set Cursor at top mid of screen
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new SUIGetImageException("Win32 SDK Platform Exception!", e);
                }
                IntPtr hdcSrc  = IntPtr.Zero;
                IntPtr hdcDest = IntPtr.Zero;
                IntPtr hBitmap = IntPtr.Zero;
                Bitmap image   = null;
                try
                {
                    //index to solve the problem of GDR+ when run IE 2 times in one case.
                    index = ((index % 10) + 1);
                    //SUIWinAPIs.GetWindowRect(sui.WindowHandle, out rDialog);
                    int buffer = 0;
                    if ((SUIUtil.IsCurrentOSVista || SUIUtil.IsCurrentOSXP) && sui.IsWinForm && sui.Maximized)
                    {
                        buffer = 8;     // under vista need cut a little height of window
                    }
                    hdcSrc  = SUIWinAPIs.GetWindowDC(sui.WindowHandle);
                    hdcDest = SUIWinAPIs.CreateCompatibleDC(hdcSrc);
                    hBitmap = SUIWinAPIs.CreateCompatibleBitmap(hdcSrc, sui.Width - sui.X, sui.Height - sui.Y - buffer);
                    SUIWinAPIs.SelectObject(hdcDest, hBitmap);
                    SUIWinAPIs.BitBlt(hdcDest, 0, 0, sui.Width - sui.X,
                                      sui.Height - sui.Y - buffer,
                                      hdcSrc, 0, 0, 0x00CC0020);
                    image = new Bitmap(Image.FromHbitmap(hBitmap),
                                       Image.FromHbitmap(hBitmap).Width,
                                       Image.FromHbitmap(hBitmap).Height);

                    //Draw cursor image
                    if (withCursor)
                    {
                        int       cursorX = 0, cursorY = 0;
                        SUIBitmap cursorBmp = GetCursorImage(ref cursorX, ref cursorY);
                        if (cursorBmp != null)
                        {
                            Bitmap    cBmp = cursorBmp.Bitmap;
                            Rectangle r    = new Rectangle(cursorX - sui.X, cursorY - sui.Y, cBmp.Width, cBmp.Height);
                            Graphics  g    = Graphics.FromImage(image);
                            g.DrawImage(cBmp, r);
                            g.Flush();
                            cBmp.Dispose();
                        }
                    }

                    image.Save(tmpFile + index + tmpFileSuffix);
                    image.Dispose();
                    //SaveImg(image,tmpFile,ImageFormat.Bmp);
                }catch (Exception e)
                {
                    throw new SUIGetImageException("Win32 SDK Platform Exception!", e);
                }finally
                {
                    if (!hdcSrc.Equals(IntPtr.Zero))
                    {
                        SUIWinAPIs.ReleaseDC(sui.WindowHandle, hdcSrc);
                    }
                    if (!hdcDest.Equals(IntPtr.Zero))
                    {
                        SUIWinAPIs.DeleteDC(hdcDest);
                    }
                    if (!hBitmap.Equals(IntPtr.Zero))
                    {
                        SUIWinAPIs.DeleteObject(hBitmap);
                    }
                    if (image != null)
                    {
                        image.Dispose();
                    }
                }
                SUIBitmap ImageOfWindow = SUIBitmap.LoadSUIBitmap(tmpFile + index + tmpFileSuffix);

                return(ImageOfWindow);
            }
            throw new SUIGetImageException("Parameter SUIWindow sui is Null");
        }