/// <summary> /// Converts a Bitmap to Bitmap source /// </summary> /// <param name="bitmap">The bitmap to convert</param> /// <returns>The converted object</returns> public static BitmapSource CreateBitmapSourceFromGdiBitmap(Bitmap bitmap) { Rectangle rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height); BitmapData bitmapData = bitmap.LockBits( rect, ImageLockMode.ReadWrite, Drawing.Imaging.PixelFormat.Format32bppArgb); try { int size = (rect.Width * rect.Height) * 4; return(BitmapSource.Create( bitmap.Width, bitmap.Height, bitmap.HorizontalResolution, bitmap.VerticalResolution, PixelFormats.Bgra32, null, bitmapData.Scan0, size, bitmapData.Stride)); } finally { bitmap.UnlockBits(bitmapData); } }
/// <summary> /// Frame /// </summary> internal void UpdateInput() { if (Game.GraphicsDevice.Display.Window != null) { if (Game.IsActive) { System.Drawing.Rectangle rect = Game.GraphicsDevice.Display.Window.ClientRectangle; if (IsMouseCentered) { Forms.Cursor.Position = Game.GraphicsDevice.Display.Window.PointToScreen(new Drawing.Point(rect.Width / 2, rect.Height / 2)); } if (IsMouseClipped) { Forms.Cursor.Clip = Game.GraphicsDevice.Display.Window.RectangleToScreen(rect); } SetCursorVisibility(!IsMouseHidden); } else { Forms.Cursor.Clip = new Drawing.Rectangle(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue); RelativeMouseOffset = Vector2.Zero; SetCursorVisibility(true); RemoveAllPressedKey(); } } Gamepad.Update(); }
public static Bitmap RealResize(Drawing.Image image, int MaxImageSizeToResize) { int rW = 0; int rH = 0; double c = 0; if (MaxImageSizeToResize > (double)image.Height) { c = ((double)image.Height / (double)MaxImageSizeToResize); rW = image.Width; rH = image.Height; } else { c = ((double)image.Height / (double)MaxImageSizeToResize); rW = (int)(image.Width / c); rH = MaxImageSizeToResize; } var destRect = new System.Drawing.Rectangle(0, 0, rW, rH); var destImage = new System.Drawing.Bitmap(rW, rH); destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); using (var graphics = Graphics.FromImage(destImage)) { graphics.CompositingMode = CompositingMode.SourceCopy; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapMode = new System.Drawing.Imaging.ImageAttributes()) { wrapMode.SetWrapMode(WrapMode.TileFlipXY); graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode); } } return(destImage); }
/// ---------------------------------------------------------------------------- void TS_WindowCoversEntireScreen(CheckType checkType) { Rect rect = m_le.Current.BoundingRectangle; Screen screen = Screen.FromPoint(new System.Drawing.Point((int)(rect.Left + ((rect.Right - rect.Left) / 2)), (int)(rect.Top + ((rect.Bottom - rect.Top) / 2)))); Drawing.Rectangle AppRect = new System.Drawing.Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height); // Normal maximized window that fills entire selected screen if (Drawing.Rectangle.Intersect(screen.WorkingArea, AppRect).Equals(AppRect)) ThrowMe(checkType, "Element does not fill the entire screen"); m_TestStep++; }
/// ---------------------------------------------------------------------------- void TS_VerifyPlacedWithinScreen(CheckType checkType) { Rect rect = m_le.Current.BoundingRectangle; Screen screen = Screen.FromPoint(new System.Drawing.Point((int)rect.Left, (int)rect.Top)); Drawing.Rectangle dRect = new System.Drawing.Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height); ThrowMeAssert(checkType, Drawing.Rectangle.Intersect(screen.WorkingArea, dRect).Equals(dRect), "Verify element is withing working area", String.Format("Element {0} is not withing {1}", dRect, screen.WorkingArea)); m_TestStep++; }
/// <summary> /// Converts a Bitmap to Bitmap source /// </summary> /// <param name="bitmap">The bitmap to convert</param> /// <returns>The converted object</returns> public static BitmapSource CreateBitmapSourceFromGdiBitmap(Bitmap bitmap) { var rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height); var bitmapData = bitmap.LockBits( rect, ImageLockMode.ReadWrite, Drawing.Imaging.PixelFormat.Format32bppArgb); try { var size = (rect.Width * rect.Height) * 4; return BitmapSource.Create( bitmap.Width, bitmap.Height, bitmap.HorizontalResolution, bitmap.VerticalResolution, PixelFormats.Bgra32, null, bitmapData.Scan0, size, bitmapData.Stride); } finally { bitmap.UnlockBits(bitmapData); } }