/// <summary> /// get the bounding box properties for a particular color on the screen /// </summary> public BoundingBoxProperties getBoundingBoxProperties(System.Windows.Media.Color myColor) { BoundingBoxProperties rValue = new BoundingBoxProperties(); rValue.top = rValue.left = rValue.right = rValue.bottom = rValue.width = rValue.height = 0; System.Drawing.Color checkColor; checkColor = System.Drawing.Color.FromArgb(myColor.A,myColor.R,myColor.G,myColor.B); this.screen = ImageUtility.CaptureScreen(internalHWnd, true); try { System.Drawing.Rectangle myRect = ImageUtility.GetBoundingBoxForColor(this.screen, checkColor); rValue.top = myRect.Top; rValue.left = myRect.Left; rValue.right = myRect.Right; rValue.bottom = myRect.Bottom; rValue.width = myRect.Width; rValue.height = myRect.Height; } catch (System.Runtime.InteropServices.COMException ex) { logComment(" Error in ImageUtils: " + ex); } logComment(" Bounding box for color: " + checkColor.A.ToString() + " " + checkColor.R.ToString()+ " " + checkColor.G.ToString()+ " " + checkColor.B.ToString()); logComment(" L: " + rValue.left + " R: " + rValue.right + " T: " + rValue.top + " B: " + rValue.bottom + " -- H: " + rValue.height + " W: " + rValue.width + "\n"); return rValue; }
/// <summary> /// Take a snaphot of the screen bounded by rectangle /// </summary> public void ScreenSnapshot(Rectangle rectangle) { Bitmap bmpCapture = ImageUtility.CaptureScreen(rectangle); OriginalData.Image = new ImageAdapter(bmpCapture); FilteredData.Image = new ImageAdapter(bmpCapture); bmpCapture.Dispose(); }
/// <summary> /// Takes a Snapshot of the HWND screen area /// </summary> /// <param name="HWND">The HWND of the window to take a snapshot for</param> /// <param name="clientAreaOnly">Direct to get the client area or the full window</param> /// <returns></returns> /// Note : Passing an invalid HWND will throw an exception public void ScreenSnapshot(IntPtr HWND, bool clientAreaOnly) { Bitmap bmpCapture = ImageUtility.CaptureScreen(HWND, clientAreaOnly); //, out rect); OriginalData.Image = new ImageAdapter(bmpCapture); FilteredData.Image = new ImageAdapter(bmpCapture); bmpCapture.Dispose(); }
/// <summary> /// Return the color on the screen at a certain point /// </summary> public System.Windows.Media.Color getColorAtPoint(int X, int Y) { this.screen = ImageUtility.CaptureScreen(internalHWnd, true); System.Drawing.Color myColor = System.Drawing.Color.FromArgb(0x00, 0x00, 0x00, 0x00); try { myColor = screen.GetPixel(X,Y); } catch (System.Runtime.InteropServices.COMException ex) { logComment(" Error in ImageUtils: " + ex); return Colors.Black; } logComment(" Color at position " + X.ToString() + " " + Y.ToString() + " was " + myColor.A.ToString() + " " + myColor.R.ToString()+ " " + myColor.G.ToString()+ " " + myColor.B.ToString()); System.Windows.Media.Color returnColor = System.Windows.Media.Color.FromArgb(myColor.A,myColor.R,myColor.G,myColor.B); return returnColor; }
/****************************************************************************** * Function: Verify ******************************************************************************/ /// <summary> /// Side by Side verification call to perform verifcation for a specific time /// </summary> public bool Verify(double curTime) { // if there is no window registered, we can't proceede if (!windowRegistered) { verboseLog += "\n COULD NOT DO VISUAL VALIDATION!!!!!!!!!!! No Window was specified. Defaulting to ValuesOnlyVerify. For VisualValidation, use the following constructor: SideBySideVerifier(Window win) "; return(ValuesOnlyVerify(curTime)); } bool passResult = true; bool valuesCheckOK = true; // Snapshot System.Threading.Thread.Sleep(150); this.aniWin.Title = windowTitle; System.Drawing.Bitmap animatedCapture = ImageUtility.CaptureScreen(hWnd, true); // Set BaseValue to AnimationCalculator Value verboseLog = "\n Side by Side Verifier for time " + curTime; if ((registeredAnimatableCount == 0) && (registeredUIElementCount == 0)) { verboseLog += " No animations could be registered - nothing to verify"; return(false); } // walk all registered animatables, obtain expected and actual values and compare for (int i = 0; i < registeredAnimatableCount; i++) { object expectedValue = myValidator.Verify(registeredAnimatableObjs[i].animClock, registeredAnimatableObjs[i].baseValue, curTime); DependencyObject current = registeredAnimatableObjs[i].animObj; object currentValue = current.GetValue(registeredAnimatableObjs[i].animProp); verboseLog += "\n" + current.GetType().ToString().Substring(current.GetType().ToString().LastIndexOf(".") + 1); verboseLog += " " + registeredAnimatableObjs[i].animProp.ToString().Substring(registeredAnimatableObjs[i].animProp.ToString().LastIndexOf(".") + 1) + " Anim:: prog: "; verboseLog += registeredAnimatableObjs[i].animClock.CurrentProgress.ToString() + " exp : " + expectedValue.ToString() + " act: " + currentValue.ToString(); if (!myValidator.WithinTolerance(currentValue, expectedValue, this.toleranceInPercent)) { passResult = false; verboseLog += " <-----"; valuesCheckOK = false; } current.SetValue(registeredAnimatableObjs[i].animProp, expectedValue); ((System.Windows.Media.Animation.Animatable)current).ApplyAnimationClock(registeredAnimatableObjs[i].animProp, null); } // walk all registered UI Elements, obtain expected and actual values and compare for (int i = 0; i < registeredUIElementCount; i++) { object expectedValue = myValidator.Verify(registeredUIElementObjs[i].animClock, registeredUIElementObjs[i].baseValue, curTime); object currentValue = registeredUIElementObjs[i].animObj.GetValue(registeredUIElementObjs[i].animProp); UIElement current = registeredUIElementObjs[i].animObj; verboseLog += "\n" + current.GetType().ToString().Substring(current.GetType().ToString().LastIndexOf(".") + 1); verboseLog += registeredUIElementObjs[i].animProp.ToString().Substring(registeredUIElementObjs[i].animProp.ToString().LastIndexOf(".") + 1) + " Anim:: prog: "; verboseLog += registeredUIElementObjs[i].animClock.CurrentProgress.ToString() + " exp : " + expectedValue.ToString() + " act: " + currentValue.ToString(); // check to make sure the values match. If they do, setting valuesCheckOk to if (!myValidator.WithinTolerance(currentValue, expectedValue, this.toleranceInPercent)) { passResult = false; verboseLog += " <-----"; valuesCheckOK = false; } current.SetValue(registeredUIElementObjs[i].animProp, expectedValue); current.ApplyAnimationClock(registeredUIElementObjs[i].animProp, null); } // obviously, if the calculated and actual values do not match, there is no need for visual validation if (valuesCheckOK) { // Snapshot System.Drawing.Bitmap staticCapture = ImageUtility.CaptureScreen(hWnd, true); // Visual Verification passResult = imageCompare.Compare(new ImageAdapter(staticCapture), new ImageAdapter(animatedCapture)); if (!passResult) { verboseLog += "\n The comparison has failed. Anim_" + curTime.ToString() + ".bmp and Static_" + curTime.ToString() + ".bmp have been written out"; animatedCapture.Save("Anim_" + curTime.ToString() + ".bmp"); staticCapture.Save("Static_" + curTime.ToString() + ".bmp"); } } else { verboseLog += "\n VISUAL VALIDATION SKIPPED!!!!!!!!!!! The values did not match, no sense comparing"; passResult = false; } // Now lets put the animations back for (int i = 0; i < registeredAnimatableCount; i++) { DependencyObject current = registeredAnimatableObjs[i].animObj; current.SetValue(registeredAnimatableObjs[i].animProp, registeredAnimatableObjs[i].baseValue); ((System.Windows.Media.Animation.Animatable)current).ApplyAnimationClock(registeredAnimatableObjs[i].animProp, registeredAnimatableObjs[i].animClock); } for (int i = 0; i < registeredUIElementCount; i++) { UIElement current = registeredUIElementObjs[i].animObj; current.SetValue(registeredUIElementObjs[i].animProp, registeredUIElementObjs[i].baseValue); current.ApplyAnimationClock(registeredUIElementObjs[i].animProp, registeredUIElementObjs[i].animClock); } return(passResult); }