/// <summary> /// Creates a ScaledBitmap from the given original bitmap and replace it's transparent pixels with the /// given new color. /// </summary> /// <param name="originalBmp">The original bitmap.</param> /// <param name="transparentColor">The selected transparent color on the original bitmap.</param> /// <param name="replaceTo"> /// The transparent pixels on the original bitmap will be replaced with this color. /// </param> /// <returns>The created ScaledBitmap.</returns> /// <remarks>Disposing originalBmp is the responsibility of the caller.</remarks> public static ScaledBitmap FromBitmap(Bitmap originalBmp, Color transparentColor, Color replaceTo) { if (null == originalBmp) { throw new ArgumentNullException("originalBmp"); } if (PixelFormat.Format24bppRgb != originalBmp.PixelFormat) { throw new ArgumentException("Pixel format of the given Bitmap must be PixelFormat.Format24bppRgb", "originalBmp"); /// TODO: implement other pixel format support (?) } ScaledBitmap original = ScaledBitmap.FromBitmap(originalBmp); ScaledBitmap retBmp = new ScaledBitmap(original.Width, original.Height); BitmapAccess retBmpAccess = BitmapAccess.FromBitmap(retBmp); retBmpAccess.Clear(replaceTo); original.MakeTransparent(transparentColor); retBmpAccess.DrawBitmap(original, 0, 0); retBmpAccess.Dispose(); original.Dispose(); return(retBmp); }
/// <summary> /// Constructs a ViewPortRefreshMgr object. /// </summary> /// <param name="targetVP">The target ViewPort that this refresh manager is responsible for.</param> public ViewPortRefreshMgr(ViewPort targetVP, BitmapAccess frameBufferAccess) { if (null == targetVP) { throw new ArgumentNullException("targetVP"); } if (null == frameBufferAccess) { throw new ArgumentNullException("frameBufferAccess"); } this.targetVP = targetVP; this.frameBufferAccess = frameBufferAccess; this.drawAccessGranted = false; this.dirtyRectsVPC = new List <Rectangle>(); this.dirtyRectsDC = new List <Rectangle>(); this.invalidate = true; }
/// <summary> /// Creates a Display object with the given width, height, vertical and horizontal scale and background color. /// </summary> /// <param name="width">The width of the Display (in logical pixels).</param> /// <param name="height">The height of the Display (in logical pixels).</param> /// <param name="horzScale">The horizontal scaling factor of the Display.</param> /// <param name="vertScale">The vertical scaling factor of the Display.</param> /// <param name="background">The background color of the created Display.</param> /// <returns> /// A reference to the newly created Display or a null pointer if the Display already exists. /// </returns> /// <remarks> /// If the Display already exists, you can get a reference to it with the Display.Instance property. /// </remarks> public static Display Create(int width, int height, int horzScale, int vertScale, Color background) { if (null == instance) { instance = new Display(width, height, horzScale, vertScale, background); /// Initialize the frame buffer only after the instance has been successfully created. /// See the comment in the private constructor of the Display for more information. instance.frameBuffer = new ScaledBitmap(width, height); instance.frameBufferAccess = BitmapAccess.FromBitmap(instance.frameBuffer); instance.frameBufferAccess.Clear(instance.backgroundColor); return(instance); } else { return(null); } }
/// <summary> /// Creates a ScaledBitmap from the given original bitmap and replace it's transparent pixels with the /// pixels of another bitmap. /// </summary> /// <param name="originalBmp">The original bitmap.</param> /// <param name="transparentColor">The selected transparent color on the original bitmap.</param> /// <param name="replaceTo"> /// The transparent pixels on the original bitmap will be replaced with the pixels of this bitmap. /// </param> /// <returns>The created ScaledBitmap.</returns> /// <remarks>Disposing originalBmp and replaceTo is the responsibility of the caller.</remarks> public static ScaledBitmap FromBitmap(Bitmap originalBmp, Color transparentColor, Bitmap replaceTo) { if (null == originalBmp) { throw new ArgumentNullException("originalBmp"); } if (null == replaceTo) { throw new ArgumentNullException("replaceTo"); } if (PixelFormat.Format24bppRgb != originalBmp.PixelFormat || PixelFormat.Format24bppRgb != replaceTo.PixelFormat) { throw new ArgumentException("Pixel format of the given Bitmaps must be PixelFormat.Format24bppRgb"); /// TODO: implement other pixel format support (?) } ScaledBitmap original = ScaledBitmap.FromBitmap(originalBmp); ScaledBitmap replaceToBmp = ScaledBitmap.FromBitmap(replaceTo); ScaledBitmap retBmp = new ScaledBitmap(original.Width, original.Height); BitmapAccess retBmpAccess = BitmapAccess.FromBitmap(retBmp); for (int currX = 0; currX < retBmp.Width; currX = currX + replaceTo.Width) { for (int currY = 0; currY < retBmp.Height; currY = currY + replaceTo.Height) { retBmpAccess.DrawBitmap(replaceToBmp, currX, currY); } } original.MakeTransparent(transparentColor); retBmpAccess.DrawBitmap(original, 0, 0); retBmpAccess.Dispose(); original.Dispose(); replaceToBmp.Dispose(); return(retBmp); }